Skip to content

Instantly share code, notes, and snippets.

@kynatro
Last active August 29, 2015 14:05
Show Gist options
  • Save kynatro/337e3dc093cd121094a5 to your computer and use it in GitHub Desktop.
Save kynatro/337e3dc093cd121094a5 to your computer and use it in GitHub Desktop.
Prevent Window Scroll
;(function($, window, undefined){
// Prevent scrolling on a page
$(window).on('mousewheel keydown', function(event){
// Un-comment to only prevent scrolling when an arbitrary global is true
// if(window.preventScroll) return;
// Only prevent default on specific key presses (pageup, pagedown, end, home, left, up, right, down)
if(event.type == "keydown"){
if($.inArray(event.keyCode, [33, 34, 35, 36, 37, 38, 39, 40]) !== -1) event.preventDefault();
}
// Prevent on mousewheel all the time
else {
event.preventDefault();
}
});
})(jQuery, window, null);

Prevent scrolling of the main viewport using a simple jQuery bind. Requires jQuery and a mousewheel plugin to operate properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment