Skip to content

Instantly share code, notes, and snippets.

@jrainlau
Created August 29, 2016 07:28
Show Gist options
  • Save jrainlau/e9b026549aef0c3cc41462b7911b8410 to your computer and use it in GitHub Desktop.
Save jrainlau/e9b026549aef0c3cc41462b7911b8410 to your computer and use it in GitHub Desktop.
滚动方向
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