简体   繁体   English

简单滚动到顶部过渡不起作用

[英]Simple Scroll to Top transition not working

Trying to make a simple scroll to top button that smoothly scrolls up and I thought this would make it work. 试图制作一个简单的滚动到顶部按钮,使其平滑地向上滚动,我认为这将使其起作用。

Right now all it does is make the page shoot right to the top so it is working at least sort of correct just the delay isn't working, I'm no expert on jQuery/Javascript and can't quite figure it out. 现在所做的只是使页面从右上角拍摄,因此它至少在正确的程度上起作用,只是延迟不起作用。我不是jQuery / Javascript专家,也不太清楚。

$('.top').click(function(){

    var scrollPosition = $('.scrollfix').scrollTop();

    while (scrollPosition > 0 ) {
        $('.scrollfix').delay(1).scrollTop(scrollPosition);
        scrollPosition--;
    }
});

You can see it in use here: http://jsfiddle.net/JamesKyle/8H7hR/101/ 您可以在这里查看其使用情况: http : //jsfiddle.net/JamesKyle/8H7hR/101/

$('.top').click(function(){
    $('.scrollfix').animate({scrollTop : 0},1000);
});

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

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