Slow down scroll to top event by jQuery animate

前端 未结 4 856
野趣味
野趣味 2020-11-29 03:10

I\'d like my page to go to the top when certain anchor is clicked.

Here is how I tried to do it but it\'s not working, it\'s scrolling super fast.

          


        
相关标签:
4条回答
  • 2020-11-29 03:53
    $('a[href=\\#top]').click(function(){
      $('body').animate(
        {
          scrollTop: 0
        }, 
        2000
      );
    });
    

    The # should be escaped \\#.

    0 讨论(0)
  • 2020-11-29 03:57

    When you pass 50 as the second parameter to animate, that is 50 milliseconds. See the animate documentation. Either pass a larger number, or as c0mrade suggested, simply pass 'slow' .

    0 讨论(0)
  • 2020-11-29 04:04

    you can set the time for scroll top

    $('a[href=#top]').click(function(){
     $('body').animate({
         scrollTop: 0},4000);});
    
    0 讨论(0)
  • 2020-11-29 04:08
    $('a[href=#top]').click(function(){
        $('html, body').animate({scrollTop:0}, 'slow');
    });
    

    Perhaps?

    0 讨论(0)
提交回复
热议问题