8

Possible Duplicate:
jQuery scroll To Element

Basically, I want my user to be instantly scroll down to a specific anchor tag just like they do with a hashtag. However, I can't use a hashtag and therefore want to scroll them down using javascript (preferably jquery).

Any thoughts on how to do this?

Community
  • 1
  • 1
Spencer
  • 17,912
  • 32
  • 79
  • 116
  • Take a look at http://stackoverflow.com/questions/6677035/jquery-scroll-to-element – Grim... Jan 24 '12 at 16:12
  • What? A hashtag is a means of categorising things on Twitter. What does that have to do with scrolling? Do you mean [fragment identifier](http://en.wikipedia.org/wiki/Fragment_identifier) / [anchors](http://www.w3.org/TR/html4/struct/links.html#h-12.2.3)? – Quentin Jan 24 '12 at 16:14
  • 1
    @Quentin, where do you think the idea of hashtags came from? – zzzzBov Jan 24 '12 at 16:18
  • @Quentin did you really have trouble understanding what I meant? Was that comment really necessary? – Spencer Jan 24 '12 at 16:20

1 Answers1

6

This will jump instantly to the element matched by $(selector):

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

If you want a fluid animation:

$(document.body).animate({'scrollTop': $(selector).offset().top}, duration);
zzzzBov
  • 157,699
  • 47
  • 307
  • 349