[英]How to throttle function using the mousewheel plugin?
我正在使用這個插件: https : //github.com/jquery/jquery-mousewheel
這是一個水平滾動的一頁站點,該功能旨在用作“ scrollsnap”-當前部分上的滾動將強制將其捕捉到下一部分。 但是,在第一個“快照”之后,它只會在大約5秒鍾后發生,我認為這是由於函數連續觸發了太多次。
function scrollSnap() {
$('.page:not(:last-child)').each(function(){
var nextTarget = $(this).next().position().left;
$(this).mousewheel(function(){
if(event.deltaY >= 50) {
$('main').animate({
scrollLeft: nextTarget
}, 700);
console.log("scrolled to: ", nextTarget);
}
});
});
$('.page:not(:first-child)').each(function(){
var prevTarget = $(this).prev().position().left;
$(this).mousewheel(function(){
if(event.deltaY <= -50) {
$('main').animate({
scrollLeft: prevTarget
}, 700);
console.log("scrolled to: ", prevTarget);
}
});
});
}
$(document).ready(function() {
scrollSnap();
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.