user2390342
user2390342

Reputation: 33

Jquery click event to target anchor not working in Firefox

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 );
});

Upvotes: 1

Views: 852

Answers (1)

Blake Plumb
Blake Plumb

Reputation: 7199

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.

Upvotes: 1

Related Questions