Skip to content

Instantly share code, notes, and snippets.

@sasknot
Last active February 4, 2016 07:23
Show Gist options
  • Save sasknot/975b5d6b73ff3c4f5475 to your computer and use it in GitHub Desktop.
Save sasknot/975b5d6b73ff3c4f5475 to your computer and use it in GitHub Desktop.
Prevent scroll
# Functions to disable/enable scroll
scrollPreventDefault = (e) ->
e = e or window.event
if e.preventDefault
e.preventDefault()
e.returnValue = false
keydown = (e) ->
t = [37,38,39,40]
n = t.length
while n--
if e.keyCode == t[n]
scrollPreventDefault e
wheel = (e) ->
scrollPreventDefault e
disableScroll = ->
if window.addEventListener
window.addEventListener 'DOMMouseScroll', wheel, false
window.onmousewheel = document.onmousewheel = wheel
document.onkeydown = keydown
document.ontouchmove = (e) ->
e.preventDefault()
enableScroll = ->
if window.removeEventListener
window.removeEventListener 'DOMMouseScroll', wheel, false
window.onmousewheel = document.onmousewheel = document.onkeydown = null
document.ontouchmove = (e) ->
true
// Functions to disable/enable scroll
function scrollPreventDefault(e){e=e||window.event;if(e.preventDefault){e.preventDefault();}e.returnValue=false;}function keydown(e){var t=[37,38,39,40];for(var n=t.length;n--;){if(e.keyCode===t[n]){scrollPreventDefault(e);return;}}}function wheel(e){scrollPreventDefault(e);}function disableScroll(){if(window.addEventListener){window.addEventListener("DOMMouseScroll",wheel,false);}window.onmousewheel=document.onmousewheel=wheel;document.onkeydown=keydown;document.ontouchmove=function(e){e.preventDefault();};}function enableScroll(){if(window.removeEventListener){window.removeEventListener("DOMMouseScroll",wheel,false);}window.onmousewheel=document.onmousewheel=document.onkeydown=null;document.ontouchmove=function(e){return true;};}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment