scrollTop jquery, scrolling to div with id?

前端 未结 5 2032
面向向阳花
面向向阳花 2020-12-24 07:08

So this is the current code I have

$(document).ready(function() {
    $(\'.abouta\').click(function(){
        $(\'html, body\').animate({scrollTop:308}, \'s         


        
5条回答
  •  执念已碎
    2020-12-24 07:29

    instead of

    $('html, body').animate({scrollTop:xxx}, 'slow');
    

    use

    $('html, body').animate({scrollTop:$('#div_id').position().top}, 'slow');
    

    this will return the absolute top position of whatever element you select as #div_id

提交回复
热议问题