1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| function addEvent(el, type, callback, useCapture ){ if(el.dispatchEvent){ el.addEventListener( type, callback, !!useCapture ); }else { el.attachEvent( "on"+type, callback ); } return callback; } var wheel = function(obj,callback){ var wheelType = "mousewheel" try{ document.createEvent("MouseScrollEvents") wheelType = "DOMMouseScroll" }catch(e){} addEvent(obj, wheelType,function(event){ if ("wheelDelta" in event){ var delta = event.wheelDelta if( window.opera && opera.version() < 10 ) delta = -delta; event.delta = Math.round(delta) /120; }else if( "detail" in event ){ event.wheelDelta = -event.detail * 40 event.delta = event.wheelDelta /120 } callback.call(obj,event); }); } wheel(document,function(e){ console.log(e.delta); var h = document.body.scrollTop || document.documentElement.scrollTop; if (e.delta >= 0 && h <= 0) { console.log('向上滚动---' + e.delta); swiper1.enableMousewheelControl(); } });
|