»
S
I
D
E
B
A
R
«
jQuery – Scrolling an Element into View
May 30th, 2010 by admin

If you need to scroll the window to make an element into view, you can use the offset method to determine the location of the destination element relative to the document and then use the scrollTop method to scroll the document to bring the element into view.

For example, let’s say you want to scroll to the #links element when the user clicks the #related element:

jQuery('#related').click(function() {
    var fooOffset = jQuery('#links').offset(),
        destination = fooOffset.top;
    jQuery(document).scrollTop(destination);
});
Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay



Similar Posts:
Leave a Reply

Powered by WP Hashcash