Run ScrollTop with offset of element by ID

前端 未结 2 811
一个人的身影
一个人的身影 2020-12-07 14:30

Trying to make the browser scroll to a specific ID with an added offset -

$(\'html, body\').animate({scrollTop: $(\'#contact\').offset().top}, \'slow\');
         


        
2条回答
  •  自闭症患者
    2020-12-07 15:25

    No magic involved, just subtract from the offset top of the element

    $('html, body').animate({scrollTop: $('#contact').offset().top -100 }, 'slow');
    

提交回复
热议问题