Created
September 28, 2012 18:55
-
-
Save acemir/3801527 to your computer and use it in GitHub Desktop.
Cross-Browser Enable or Disable MouseScroll Temporanly
This file contains hidden or 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
| // left: 37, up: 38, right: 39, down: 40, | |
| // spacebar: 32, pageup: 33, pagedown: 34, end: 35, home: 36 | |
| 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 disable_scroll() { | |
| if (!window.addEventListener) { window.attachEvent('onDOMMouseScroll', wheel, false);} | |
| else { window.addEventListener('DOMMouseScroll', wheel, false);} | |
| window.onmousewheel = document.onmousewheel = wheel; | |
| document.onkeydown = keydown; | |
| } | |
| function enable_scroll() { | |
| if (!window.removeEventListener) { window.detachEvent('onDOMMouseScroll', wheel); } | |
| else {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