我想禁用滚动事件监听器一段时间
我在这里实现了滑块
我的代码在这里
$(window).bind('DOMMouseScroll', function (e) {
if (e.originalEvent.detail > 0) {
//scroll down
if(swiperV.activeSlide<(total-1)){
console.log('down');
swiperV.swipeNext();
console.log('down-after');
}
} else {
//scroll up
if(swiperV.activeSlide>0){
console.log('up');
swiperV.swipePrev();
console.log('up-after');
}
}
//prevent page fom scrolling
return false;
});
现在我要禁用滚动,直到幻灯片更改
当我调用swiperV.swipeNext()时;它将改变幻灯片。
最佳答案
所以最后使用
用于Firefox
$(window).bind('DOMMouseScroll', function (e) {
$(window).unbind('DOMMouseScroll');
if (e.originalEvent.detail > 0) {
if(swiperV.activeSlide<(total-1)){
swiperV.swipeNext();
$(window).bind('DOMMouseScroll');
}
}
else {
if(swiperV.activeSlide>0){
swiperV.swipePrev();
$(window).bind('DOMMouseScroll');
}
}
return false;
});
对于其他
$(window).bind('mousewheel', function (e) {
$(window).unbind('mousewheel');
if (e.originalEvent.wheelDelta < 0) {
//scroll down total
if(swiperV.activeSlide<(total-1)){
swiperV.swipeNext();
$(window).bind('mousewheel');
}
} else {
//scroll up
if(swiperV.activeSlide>0){
swiperV.swipePrev();
$(window).bind('mousewheel');
}
}
//prevent page fom scrolling
return false;
});
多亏了adeneo和Ishan Jain
关于javascript - 禁用滚动事件监听器一段时间,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17759456/