我正在構建網頁。它看起來像單個頁面,但我正在處理sections.On點擊按鈕控件我隱藏所有部分,並顯示在屏幕上的特定部分。 所以,我可以做同樣的控制與鼠標墊上下滾動嗎?我已經在谷歌檢查,我無法得到適當的解決方案。 如果這個問題已經發布,請給我提供參考鏈接。如何使用jQuery/JavaScript檢測觸摸板滾動
0
A
回答
0
可以使用scroll event來響應用戶的滾動,像這樣:
$("#target").scroll(function(event) {
console.log("scroll event received:", event);
});
注意,滾動事件非常頻繁觸發,所以,如果你做任何事情,使瀏覽器的工作辛苦,你應該小心扼殺事件,即確保您每x毫秒左右執行一次代碼。
如果您只想在滾動停止後執行代碼,請使用I have this fiddle for you。
function checkf(predf, callback, ms) {
window.setTimeout(function() {
if (predf()) {
callback();
return;
}
checkf(predf, callback, ms);
}, ms);
}
function afterScrollStops(func) {
var ms = 100, // interval to perform the scroll position check
oldX = $(document).scrollLeft(),
oldY = $(document).scrollTop();
function startf() {
$(document).one("scroll", function() {
checkf(function() {
var newX = $(document).scrollLeft(),
newY = $(document).scrollTop(),
stoppedScrolling = newX === oldX && newY === oldY;
oldX = newX;
oldY = newY;
return stoppedScrolling;
}, function() {
func();
startf();
}, ms);
});
}
startf();
}
afterScrollStops(function() {
console.log("user stopped scrolling");
});
在本例中,傳遞給afterScrollStops用戶已經停止滾動之後執行功能的回調函數。
+0
當然,謝謝。我會查一下 –
相關問題
- 1. TapgestureRecogniser檢測到觸摸滾動型爲
- 2. 觸摸後如何檢測觸摸
- 3. 使用libgdx觸摸滾動
- 4. 滾動SpriteNode使用觸摸
- 5. 如何檢測滾動視圖的觸摸?
- 6. 如何使用jQuery檢測觸摸設備上的向下滾動?
- 7. javascript滾動觸摸滾動
- 8. iScroll 5使用鼠標滾輪和觸摸滾動的容器邊界檢測
- 9. 如何使用51degrees.mobi檢測觸摸屏移動設備
- 10. 檢測觸摸板的座標
- 11. 在mac上滾動的觸摸板
- 12. 觸摸板滾動問題jQuery
- 13. Vim滾動觸摸板太敏感
- 14. 在煎茶觸摸滾動面板
- 15. 觸摸板橫向滾動emacs
- 16. 觸摸不檢測?
- 17. android檢測觸摸
- 18. android檢測觸摸
- 19. 檢測CAShapeLayer觸摸
- 20. 檢測觸摸UIButton
- 21. UINavigationItem:檢測觸摸
- 22. 檢測用戶觸摸UIScrollView
- 23. 檢測觸摸動畫(移動)視圖
- 24. 如何檢測何時觸摸drawable
- 25. 使用UIButton進行觸摸檢測
- 26. 如何在觸摸UIButton時通過UIView檢測觸摸?
- 27. 使用Chrome阻止水平觸摸板在Macbook上滾動?
- 28. 使用原型的觸摸滾動
- 29. 以編程方式檢測滾動視圖之外的觸摸
- 30. 的UIScrollView - 檢測第二觸摸而滾動
你試過嗎 - > https://api.jquery.com/scroll/ – N1gthm4r3
是的,我試過了。但我沒有得到正確的迴應 –
我認爲有完美的解決方案來檢測觸摸板滾動,但有解決辦法。三角洲速度增加了40倍。從那裏你可以檢測到它。有關更多信息,請查看此答案:https://stackoverflow.com/a/16696129/631803 – VicJordan