jQuery scrollTop() method not working

前端 未结 4 2465
花落未央
花落未央 2021-02-19 19:53

I have the following jQuery code

$(document).ready(function () {
    $(\'.navtoTop\').click(function(){
           $(\"html\").scrollTop( $(\"#topofthePage\").of         


        
4条回答
  •  不思量自难忘°
    2021-02-19 20:15

    You already got an answer on this. But, since you also want a smooth scrolling, consider the following alternative:

    $('.navtoTop').click(function(){
        $('html, body').animate({
            scrollTop: $('#topofthePage').offset().top
        }, 1000);
    }); 
    

提交回复
热议问题