2012-01-24 23 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);