//防止特定时间内多次触发鼠标滚轮操作
var flag_mouse;
function rst_flag_mouse() {
flag_mouse = false;
}
var scrollFunc = function(e) {
e = e || window.event;
// window.addEventListener ? window.addEventListener("DOMMouseScroll", this.wheel, false) : null;
if (e.wheelDelta) {
//第一步:先判断浏览器IE,谷歌滑轮事件
if (e.wheelDelta > 50) {
//当滑轮向上滚动时
if (flag_mouse == false) {
flag_mouse = true;
setTimeout(function() {
rst_flag_mouse();
}, 500);
// console.log("滑轮向上滚动");
swiper_outside.slidePrev();
} else {
// console.log("滑轮向上滚动");
}
}
if (e.wheelDelta < 50) {
if (flag_mouse == false) {
flag_mouse = true;
setTimeout(function() {
rst_flag_mouse();
}, 500);
//当滑轮向下滚动时
// console.log("滑轮向下滚动");
swiper_outside.slideNext();
}
}
} else if (e.detail) {
//Firefox滑轮事件
if (e.detail < 0) {
if (flag_mouse == false) {
flag_mouse = true;
setTimeout(function() {
rst_flag_mouse();
}, 500);
//当滑轮向上滚动时
// console.log("滑轮向上滚动");
swiper_outside.slidePrev();
}
}
if (e.detail > 0) {
if (flag_mouse == false) {
flag_mouse = true;
setTimeout(function() {
rst_flag_mouse();
}, 500);
//当滑轮向下滚动时
// console.log("滑轮向下滚动");
swiper_outside.slideNext();
}
}
}
}; //给页面绑定滑轮滚动事件
if (document.addEventListener) {
//firefox
document.addEventListener("DOMMouseScroll", scrollFunc, false);
} //滚动滑轮触发scrollFunc方法 //ie 谷歌
window.onmousewheel = document.onmousewheel = scrollFunc;
评论区