Skip to content

Instantly share code, notes, and snippets.

@sstephenson
Created June 23, 2009 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sstephenson/134653 to your computer and use it in GitHub Desktop.
Save sstephenson/134653 to your computer and use it in GitHub Desktop.
preserving_scroll_position.js
Element.addMethods({
preservingScrollPosition: function(element, callback) {
element = $(element);
var offset = element.cumulativeOffset().top - document.viewport.getScrollOffsets().top;
callback();
window.scrollTo(0, element.cumulativeOffset().top - offset);
return element;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment