简体   繁体   English

jQuery ScrollTo插件无法滚动到Firefox上的元素

[英]jQuery ScrollTo plugin does not scroll to the element on Firefox

I'm using the scrollTo plugin by Ariel Flesler to scroll to an element. 我正在使用Ariel Flesler的scrollTo插件滚动到某个元素。 However this piece of code just doesn't run on Firefox (v 61). 但是,这段代码无法在Firefox(v 61)上运行。

$(document).ready(function(){
    $('html, body').scrollTo(document.getElementById('login-link'), 800);
});

Here's a demo: https://jsfiddle.net/1n26s3dm/1/ 这是一个演示: https : //jsfiddle.net/1n26s3dm/1/

Any idea what am I doing wrong? 知道我在做什么错吗?

Add the following code and make sure you have jQuery installed, because on your fiddle there isn't jquery 添加以下代码,并确保已安装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');

});

Your example on jsfiddle doesn't work. 您在jsfiddle上的示例不起作用。 If you need jQuery you should select this library in JS window. 如果需要jQuery,则应在JS窗口中选择此库。 Do not use Resources for include jQuery. 不要将Resources用于jQuery。 Try my example 试试我的例子

Also try do not mix jQuery and Vanilla.js to work with DOM. 也请尝试不要将jQuery和Vanilla.js混合使用以处理DOM。 Would be better if you change your code like this: 如果这样更改代码,效果会更好:

$(document).ready(function(){
   $('html, body').scrollTo($('#login-link'), 800);
}); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM