Prevent scrolling of the main viewport using a simple jQuery bind. Requires jQuery and a mousewheel plugin to operate properly.
Last active
August 29, 2015 14:05
-
-
Save kynatro/337e3dc093cd121094a5 to your computer and use it in GitHub Desktop.
Prevent Window Scroll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;(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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment