Js实现鼠标滚轮滑动监听
2017-09-12 11:51
756 查看
在别人博客的基础上改写了一个js实现鼠标滚轮事件的监听:
windowAddMouseWheel();
function windowAddMouseWheel() {
var scrollFunc = function (e) {
e = e || window.event;
if (e.wheelDelta) { //判断浏览器IE,谷歌滑轮事件
if (e.wheelDelta > 0) { //当滑轮向上滚动时
alert("滑轮向上滚动");
}
if (e.wheelDelta < 0) { //当滑轮向下滚动时
alert("滑轮向下滚动");
}
} else if (e.detail) { //Firefox滑轮事件
if (e.detail> 0) { //当滑轮向上滚动时
alert("滑轮向上滚动");
}
if (e.detail< 0) { //当滑轮向下滚动时
alert("滑轮向下滚动");
}
}
};
//给页面绑定滑轮滚动事件
if (document.addEventListener) {
document.addEventListener('DOMMouseScroll', scrollFunc, false);
}
//滚动滑轮触发scrollFunc方法
window.onmousewheel = document.onmousewheel = scrollFunc;
}
原文地址:http://blog.sina.com.cn/s/blog_78106bb10101dgwp.html
windowAddMouseWheel();
function windowAddMouseWheel() {
var scrollFunc = function (e) {
e = e || window.event;
if (e.wheelDelta) { //判断浏览器IE,谷歌滑轮事件
if (e.wheelDelta > 0) { //当滑轮向上滚动时
alert("滑轮向上滚动");
}
if (e.wheelDelta < 0) { //当滑轮向下滚动时
alert("滑轮向下滚动");
}
} else if (e.detail) { //Firefox滑轮事件
if (e.detail> 0) { //当滑轮向上滚动时
alert("滑轮向上滚动");
}
if (e.detail< 0) { //当滑轮向下滚动时
alert("滑轮向下滚动");
}
}
};
//给页面绑定滑轮滚动事件
if (document.addEventListener) {
document.addEventListener('DOMMouseScroll', scrollFunc, false);
}
//滚动滑轮触发scrollFunc方法
window.onmousewheel = document.onmousewheel = scrollFunc;
}
原文地址:http://blog.sina.com.cn/s/blog_78106bb10101dgwp.html
相关文章推荐
- 使用JS监听鼠标滚轮事件,并且滑动一次只执行一次事件方法
- 两种js监听滚轮事件的实现方法
- JS实现滚动监听以及滑动到顶部
- js实现鼠标滚轮控制图片缩放效果的方法
- 监听PC/移动端,鼠标滑动,滚轮,手指滑动事件
- 鼠标滚轮事件兼容处理、实现内容横向滑动效果
- js实现的鼠标滚轮滚动切换页面效果(类似360默认页面滚动切换效果)
- Reactjs鼠标滚轮监听
- js实现鼠标的滑动
- js鼠标滚轮上下滚动监听事件应用实例(跨浏览器,亲测)
- WPF实现鼠标滚轮滑动变更数值
- JQuery实现鼠标滚轮滑动到页面节点
- js鼠标滚轮事件详解(全兼容ie、chrome、firefox)实现图片缩放
- js实现鼠标滑动背景跟随
- js实现鼠标点击左上角滑动菜单效果代码
- js实现鼠标滚轮控制图片缩放效果的方法(转)
- 原生js利用鼠标滚轮实现滚动到当前页面实现动画效果
- 使用jQuery的Scrollify插件实现鼠标滚轮或者手势滑动到页面下一节点部分
- js实现的鼠标滚轮滚动切换页面效果(类似360默认页面滚动切换效果)