Last active
August 29, 2015 14:04
-
-
Save nowri/58f7c05d2620b8988e96 to your computer and use it in GitHub Desktop.
マウスホイールを無効にするスニペット、レガシーブラウザ対応
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
| /*global $, Modernizr */ | |
| /* | |
| * @require jquery.mousewheel.js | |
| */ | |
| function stopMouseWheel(enabled){ | |
| if(Modernizr.touch){ | |
| return; | |
| } | |
| if(enabled) { | |
| var wheel = function(event) { | |
| if(event.preventDefault){ | |
| event.preventDefault(); | |
| } | |
| event.returnValue = false; | |
| }; | |
| if(window.addEventListener) { | |
| $(window).on("mousewheel", mousewheelPreventDefaultHandler); | |
| } else { | |
| window.onmousewheel = document.onmousewheel = wheel; | |
| } | |
| } else { | |
| if(window.addEventListener) { | |
| $(window).off("mousewheel", mousewheelPreventDefaultHandler); | |
| } else { | |
| window.onmousewheel = document.onmousewheel = null; | |
| } | |
| } | |
| }; | |
| function mousewheelPreventDefaultHandler(e) { | |
| if(!window.addEventListener) { | |
| window.event.returnValue = false; | |
| return; | |
| } | |
| e.preventDefault(); | |
| e.stopPropagation(); | |
| e.returnValue = false; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment