Created
January 2, 2018 18:27
-
-
Save matthijs166/f1e2d591d28a5255f089becc63d075a5 to your computer and use it in GitHub Desktop.
disable and enable scroll lock scroll enz
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
// scroll tools | |
var keys = {37: 1, 38: 1, 39: 1, 40: 1}; | |
function preventDefault(e) { | |
e = e || window.event; | |
if (e.preventDefault) | |
e.preventDefault(); | |
e.returnValue = false; | |
} | |
function preventDefaultForScrollKeys(e) { | |
if (keys[e.keyCode]) { | |
preventDefault(e); | |
return false; | |
} | |
} | |
function disableScroll() { | |
if (window.addEventListener) // older FF | |
window.addEventListener('DOMMouseScroll', preventDefault, false); | |
window.onwheel = preventDefault; // modern standard | |
window.onmousewheel = document.onmousewheel = preventDefault; // older browsers, IE | |
window.ontouchmove = preventDefault; // mobile | |
document.onkeydown = preventDefaultForScrollKeys; | |
} | |
function enableScroll() { | |
if (window.removeEventListener) | |
window.removeEventListener('DOMMouseScroll', preventDefault, false); | |
window.onmousewheel = document.onmousewheel = null; | |
window.onwheel = null; | |
window.ontouchmove = null; | |
document.onkeydown = null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment