[英]disable scroll event listener for sometime
I want to disable scroll event listener for sometime 我想禁用滚动事件监听器一段时间
I have implemented slider here 我在这里实现了滑块
my code is here 我的代码在这里
$(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;
});
now i want to disable scroll until the slide change 现在我要禁用滚动,直到幻灯片更改
when I will call swiperV.swipeNext(); 当我调用swiperV.swipeNext()时; it will change slide.
它将改变幻灯片。
You can unbind the eventlistner by 您可以通过以下方式取消绑定事件列表
$(window).unbind('DOMMouseScroll');
you can unregister any event handler by $.unbind()
method. 您可以通过
$.unbind()
方法注销任何事件处理程序。
Name the event handler, then you can reference it within its body like so: 为事件处理程序命名,然后可以在其主体内进行引用,如下所示:
$(window).bind('DOMMouseScroll', function SomeName(e) {
if (SomeReason) $(window).unbind('DOMMouseScroll', SomeName);
}
You can unbind
event-listner and after swiperV.swipeNext();
您可以
unbind
事件列表,并且在swiperV.swipeNext();
again bind
it : - 再次
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 });
So finaly use 所以最后使用
for firefox 用于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;
});
For other 对于其他
$(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;
});
Thanks to adeneo and Ishan Jain 多亏了adeneo和Ishan Jain
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.