Skip to content

Instantly share code, notes, and snippets.

@kynatro
Last active Aug 29, 2015
Embed
What would you like to do?
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