Created
August 29, 2016 07:28
-
-
Save jrainlau/e9b026549aef0c3cc41462b7911b8410 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
var scrollFunc = function (e) { | |
var direct = 0 | |
e = e || window.event | |
if (e.wheelDelta) { //判断浏览器IE,谷歌滑轮事件 | |
if (e.wheelDelta > 0) { //当滑轮向上滚动时 | |
console.log("滑轮向上滚动") | |
} | |
if (e.wheelDelta < 0) { //当滑轮向下滚动时 | |
console.log("滑轮向下滚动") | |
} | |
} else if (e.detail) { //Firefox滑轮事件 | |
if (e.detail> 0) { //当滑轮向上滚动时 | |
console.log("滑轮向上滚动") | |
} | |
if (e.detail< 0) { //当滑轮向下滚动时 | |
console.log("滑轮向下滚动") | |
} | |
} | |
} | |
//给页面绑定滑轮滚动事件 | |
if (document.addEventListener) { | |
document.addEventListener('DOMMouseScroll', scrollFunc, false) | |
} | |
//滚动滑轮触发scrollFunc方法 | |
window.onmousewheel = document.onmousewheel = scrollFunc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment