我有一個函數可以隱藏一些標題,而框向下滾動並在滾動時出現標題。它工作正常,但如果我滾動頁面不是通過鼠標滾輪或觸摸板,並在滾動條上使用鼠標按鈕 - 事件開始重複,我的意思是如果我將通過拖動緩慢向下滾動,標題隱藏和顯示隱藏,顯示等如何通過拖動欄來執行滾動時防止.scroll()函數執行?
我想知道是否有方法來停止事件處理程序後,它已被執行一次,而鼠標按鈕被按下?
感謝。
我的代碼:
const throttleHidings = _.throttle(headerHidings, 400);
$(".data-table").scroll(throttleHidings);
function headerHidings() {
const element = $(".hiding-part"),
t = "transparent";
let scrollPosition = $(".data-table").scrollTop();
if (scrollPosition - contentScrollPosition > 0) {
scrollingDown = true;
lastPos.bottom = scrollPosition;
contentScrollPosition = scrollPosition;
}
if (scrollPosition - contentScrollPosition < 0) {
scrollingDown = false;
contentScrollPosition = scrollPosition;
lastPos.top = scrollPosition;
}
if (scrollingDown) {
hiding(scrollPosition - lastPos.top);
} else {
showing(lastPos.bottom - scrollPosition);
}
function hiding(pos) {
if (pos > 100) {
$table.height("calc(100% - 133px)");
element.slideUp(150);
}
}
function showing(pos) {
if (pos > 50) {
element.slideDown(150,() => $table.height("calc(100% - 340px)"));
}
}
}
什麼是你的代碼? – epascarello