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這樣做。 –