简体   繁体   中英

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. However this piece of code just doesn't run on Firefox (v 61).

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

Here's a demo: 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

 $('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. If you need jQuery you should select this library in JS window. Do not use Resources for include jQuery. Try my example

Also try do not mix jQuery and Vanilla.js to work with DOM. Would be better if you change your code like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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