您好,欢迎访问一九零五行业门户网

js onmousewheel事件多次触发问题解决方法_javascript技巧

我想做一个首屏和第二屏之间滚动鼠标滚轮就可以整平切换的效果,遇到了很多问题,后来在kk的帮助下,终于解决了这个问题,甚是欢喜,于是记录一下:
我最初的代码是这样的:

$(document).ready(function(){var height = $(window).height(); //获取浏览器窗口当前可见区域的大小//鼠标滚动之后整屏切换var scrollfunc = function(e){var scrolltop = document.body.scrolltop || document.documentelement.scrolltop;e = e || window.event;if((e.wheeldelta0) && scrolltop>=0 && scrolltop0 || e.detail=height && scrolltop=0 && scrolltop0 || e.detail=height && scrolltop0 || navigator.useragent.indexof(msie)>0){body = document.documentelement;}else{body = document.body;}var isfinish = true;var scrollfunc = function(e){if(isfinish){var scrolltop = body.scrolltop;e = e || window.event;if((e.wheeldelta0) && scrolltop>=0 && scrolltop0 || e.detail=height && scrolltop0){if(document.addeventlistener){document.addeventlistener('dommousescroll',scrollfunc,false);}}else{document.onmousewheel = scrollfunc;}});
终于得到简介的代码了,不得不说,通过解决这个问题,还是学到很多的。以后要向着“write less, do more”的目标更加努力了!!!
如果有哪里写的不对的,欢迎各位大神们指教,我会虚心学习的。
其它类似信息

推荐信息