[英]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.