[英]jQuery ScrollTo plugin does not scroll to the element on Firefox
我正在使用Ariel Flesler的scrollTo插件滾動到某個元素。 但是,這段代碼無法在Firefox(v 61)上運行。
$(document).ready(function(){
$('html, body').scrollTo(document.getElementById('login-link'), 800);
});
這是一個演示: https : //jsfiddle.net/1n26s3dm/1/
知道我在做什么錯嗎?
添加以下代碼,並確保已安裝jQuery,因為小提琴上沒有jquery
$('html, body').animate({
scrollTop: $("#login-link").offset().top
}, 800, function(){
// this is the callback after the animation is done
// you can emit events here
$("#login-link").trigger('click');
});
您在jsfiddle上的示例不起作用。 如果需要jQuery,則應在JS窗口中選擇此庫。 不要將Resources
用於jQuery。 試試我的例子
也請嘗試不要將jQuery和Vanilla.js混合使用以處理DOM。 如果這樣更改代碼,效果會更好:
$(document).ready(function(){
$('html, body').scrollTo($('#login-link'), 800);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.