最简单的鼠标滚动事件(鼠标滚轮的滚动事件)

最简单的鼠标滚动事件(鼠标滚轮的滚动事件)(1)

// 鼠标滚动事件 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; },

没了,结束了,是不是很简单呐,如有错误,欢迎留言.如有问题,不吝赐教。如果此篇博文对您有帮助,还请动动小手点赞 收藏 ⭐留言 呐~,谢谢 ~ ~

,

免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com

    分享
    投诉
    首页