Skip to content

Instantly share code, notes, and snippets.

@NachoMan
Created October 3, 2009 03:08
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 NachoMan/200366 to your computer and use it in GitHub Desktop.
Save NachoMan/200366 to your computer and use it in GitHub Desktop.
(function() {
function preventBehavior(e) {
e.preventDefault();
window.scrollTo(0, 0);
};
document.__defineGetter__("preventScroll", function() {
return document._preventScroll;
});
document.__defineSetter__("preventScroll", function(preventScroll) {
document._preventScroll = preventScroll;
if (preventScroll) {
document.addEventListener("touchmove", preventBehavior, false);
document.addEventListener("scroll", preventBehavior, false);
window.scrollTo(0, 0);
} else {
document.removeEventListener("touchmove", preventBehavior, false);
document.removeEventListener("scroll", preventBehavior, false);
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment