Question

I have a navigation menu that is targeting anchors that are positioned by the data-position attribute within a page. I'm using this code snippet to make this work, and it works great in Safari and Chrome, but isn't working at all in Firefox. Is there a way to fix this? Thanks in advance for any assistance you can offer!

$(document).on('click','.navigation a', function(event){
    event.preventDefault();
    var $target = $( $(this).attr('href') );
    var position = $target.data('position');
    $('body').scrollTop( position * scrollHeight );
});
Was it helpful?

Solution

Try changing your selector to

$('html, body')

Firefox overflow is applied at the html level by default. So your line of code would be

$('html, body').scrollTop( position * scrollHeight );

This question might help you as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top