javascript - JS works fine in Chrome but not in FireFox -
it's simple window scroll triggers when user clicks on nav item life of me cant seem figure out why ff wont recognise it, i've read similar q&a's recommend defining var's first i've done, appreciated.
heres code:
$("#mynavbar a").on('click', function(){ var hash = this.hash; //make sure this.hash has value if (hash !== ""){ //prevent default anchor click behavior event.preventdefault(); //use jquerys animate() method add smooth scroll $('html, body').animate({ scrolltop: $(hash).offset().top }, 800, function(){ window.location.hash = hash; }); } // end of if });
this "works" in chrome because chrome implements non-standard window.event property.
as noted in comments, should use event
argument provided jquery event handler instead.
$("#mynavbar a").on('click', function(event){ ... event.preventdefault(); ... });
Comments
Post a Comment