Run ScrollTop with offset of element by ID

匿名 (未验证) 提交于 2019-12-03 01:47:02

问题:

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

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

What I need to do is to set the offset by -100px. How can I accomplish this?

回答1:

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

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


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!