2012-01-24 24 views
2
的行为

可能重复:
jQuery scroll To Element的Javascript(最好是jQuery的),将模拟井号标签

基本上,我希望我的用户是瞬间向下滚动到一个特定的锚标记,就像他们用标签做。但是,我不能使用哈希标签,因此想要使用javascript(最好是jquery)向下滚动它们。

有关如何做到这一点的任何想法?

+0

看看 http://stackoverflow.com/questions/6677035/jquery-scroll-to-element –

+0

什么?哈希标签是在Twitter上对事物进行分类的一种手段。这与滚动有什么关系?你的意思是[片段标识符](http://en.wikipedia.org/wiki/Fragment_identifier)/ [锚点](http://www.w3.org/TR/html4/struct/links.html#h-12.2 0.3)? – Quentin

+1

@Quentin,你认为hashtags的想法是从哪里来的? – zzzzBov

回答

4

这将立即跳到由$(selector)相匹配的元素:

$(document).scrollTop($(selector).offset().top); 

如果你想有一个流畅的动画:

$(document.body).animate({'scrollTop': $(selector).offset().top}, duration);