概述
代码:
JS
// 鼠标滚动事件
windowAddMouseWheel() {
let that = this;
var scrollFunc = function (e) {
e = e || window.event;
if (e.wheelDelta) {
//判断浏览器IE,谷歌滑轮事件
if (e.wheelDelta > 0) {
//当滑轮向上滚动时
console.log("向上滚动")
}else if(e.wheelDelta < 0){
console.log("向下滚动")
}
} else if (e.detail) {
//Firefox滑轮事件
if (e.detail > 0) {
//当滑轮向上滚动时
console.log("向上滚动")
}else if (e.detail < 0) {
//当滑轮向下滚动时
console.log("向下滚动")
}
}
};
//给页面绑定滑轮滚动事件
if (document.addEventListener) {
//火狐使用DOMMouseScroll绑定
document.addEventListener("DOMMouseScroll", scrollFunc, false);
}
//其他浏览器直接绑定滚动事件
window.onmousewheel = document.onmousewheel = scrollFunc;
},
没了,结束了,是不是很简单呐,如有问题,欢迎留言。
最后:如果此篇博文对您有帮助,还请动动小手点点关注点点赞呐~,谢谢 ~ ~
最后
以上就是忧伤棒球为你收集整理的鼠标滚轮的滚动事件,判断鼠标向上还是向下滚动的全部内容,希望文章能够帮你解决鼠标滚轮的滚动事件,判断鼠标向上还是向下滚动所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复