为了账号安全,请及时绑定邮箱和手机立即绑定

firefox怎么监听鼠标滚轮滚动,这个兼容性问题怎么解决?

firefox怎么监听鼠标滚轮滚动,这个兼容性问题怎么解决?

忽然笑 2018-08-10 11:10:01
要实现的效果是在ie,chrome,firefox下监听滚轮触发事件。源码:window.onscroll=function(e){   var e =e || window.event;        var scrolltop=document.documentElement.scrollTop||document.body.scrollTop;var box = $('#qa-head');if(document.body.scrollTop >= 400){     box.addClass('fixed-head'); }else{     box.removeClass('fixed-head'); } }模拟onscroll效果if(document.addEventListener){  document.addEventListener('DOMMouseScroll',scrollFunc,false);  }window.onmousewheel=document.onmousewheel=scrollFunc;//IE/Opera/Chromevar scrollFunc=function(e){     e=e || window.event;    var t1=document.getElementById("qa-head");    if(t1.detail >= 400){         t1.addClass('fixed-head');        console.log('firefox');     }else{         t1.removeClass('fixed-head');        console.log('firefox lll');     } }但是火狐模拟onscroll的这段代码控制台都没有输出,是什么原因哪里错了?
查看完整描述

1 回答

?
慕桂英3389331

TA贡献2036条经验 获得超8个赞

函数表达式声明的函数在执行到函数体之前都是不可用的


查看完整回答
反对 回复 2018-09-19
  • 1 回答
  • 0 关注
  • 1469 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信