Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: jQuery 滚动到元素
基本上,我希望我的用户能够像使用主题标签一样立即向下滚动到特定的锚标签。但是,我不能使用主题标签,因此想使用 javascript(最好是 jquery)向下滚动它们。
关于如何做到这一点的任何想法?
这将立即跳转到匹配的元素$(selector):
$(selector)
$(document).scrollTop($(selector).offset().top);
如果你想要一个流畅的动画:
$(document.body).animate({'scrollTop': $(selector).offset().top}, duration);