1
这是一个简单的窗口滚动,当用户点击导航项目时触发,但对于我的生活我似乎无法弄清楚为什么FF不会识别它,我读过类似的Q & A的,但他们只推荐定义var的第一个我已经完成,任何帮助将不胜感激。JS在Chrome中正常工作,但不在FireFox
继承人的代码:
$("#myNavbar a").on('click', function(){
var hash = this.hash;
//make sure this.hash has a value
if (hash !== ""){
//prevent default anchor click behavior
event.preventDefault();
//use jQuerys animate() method to add smooth scroll
$('html, body').animate({
scrollTop: $(hash).offset().top
}, 800, function(){
window.location.hash = hash;
});
} // end of if
});
事件不会对范围内声明的,也许你缺少$( “#myNavbar A”)。在( '点击',函数(事件){ – juvian
你尝试换'$(文件)。 ready()'围绕你的事件处理函数吗?[jQuery.ready()](https://api.jquery.com/ready/) –
谢谢@juvian这样做。 –