Last active
August 29, 2015 14:10
-
-
Save barlas/43260fb22b20927b1c07 to your computer and use it in GitHub Desktop.
jQuery - Disable browser's scrolling method temporarily.
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
// source: http://stackoverflow.com/a/4770179/1428241 | |
var keys = [37, 38, 39, 40]; | |
function preventDefault(e) { | |
e = e || window.event; | |
if (e.preventDefault) | |
e.preventDefault(); | |
e.returnValue = false; | |
} | |
function keydown(e) { | |
for (var i = keys.length; i--;) { | |
if (e.keyCode === keys[i]) { | |
preventDefault(e); | |
return; | |
} | |
} | |
} | |
function wheel(e) { preventDefault(e); } | |
function disableScroll() { | |
if (window.addEventListener) { | |
window.addEventListener('DOMMouseScroll', wheel, false); | |
} | |
window.onmousewheel = document.onmousewheel = wheel; | |
document.onkeydown = keydown; | |
} | |
function enableScroll() { | |
if (window.removeEventListener) { | |
window.removeEventListener('DOMMouseScroll', wheel, false); | |
} | |
window.onmousewheel = document.onmousewheel = document.onkeydown = null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment