[英]disable scroll event listener for sometime
我想禁用滚动事件监听器一段时间
我在这里实现了滑块
我的代码在这里
$(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()时; 它将改变幻灯片。
您可以通过以下方式取消绑定事件列表
$(window).unbind('DOMMouseScroll');
您可以通过$.unbind()
方法注销任何事件处理程序。
为事件处理程序命名,然后可以在其主体内进行引用,如下所示:
$(window).bind('DOMMouseScroll', function SomeName(e) {
if (SomeReason) $(window).unbind('DOMMouseScroll', SomeName);
}
您可以unbind
事件列表,并且在swiperV.swipeNext();
再次bind
它:-
$(window).bind('DOMMouseScroll', function (e) {
$(window).unbind('DOMMouseScroll');
if (e.originalEvent.detail > 0) {
if(swiperV.activeSlide<(total-1)){
console.log('down');
swiperV.swipeNext();
console.log('down-after');
$(window).bind('DOMMouseScroll');
}
}
else {
if(swiperV.activeSlide>0){
console.log('up');
swiperV.swipePrev();
console.log('up-after');
$(window).bind('DOMMouseScroll');
}
}
return false;
});
对于IE,Opera,Safari,您可以使用
$(window).bind('mousewheel', function (e) { //your code });
所以最后使用
用于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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.