Scroll to the top of the page using JavaScript?

后端 未结 30 1681
借酒劲吻你
借酒劲吻你 2020-11-22 03:18

How do I scroll to the top of the page using JavaScript? The scrollbar instantly jumping to the top of the page is desirable too as I\'m not looking to achieve smooth scroll

30条回答
  •  佛祖请我去吃肉
    2020-11-22 03:36

    $(".scrolltop").click(function() {
      $("html, body").animate({ scrollTop: 0 }, "slow");
      return false;
    });
    .section{
     height:400px;
    }
    .section1{
      background-color: #333;
    }
    .section2{
      background-color: red;
    }
    .section3{
      background-color: yellow;
    }
    .section4{
      background-color: green;
    }
    .scrolltop{
      position:fixed;
      right:10px;
      bottom:10px;
      color:#fff;
    }
    
    
    Scroll top demo
    
    
    
    
    
    
    

提交回复
热议问题