我正在使用jQuery,並且需要檢測鼠標靜態時間超過2秒,然後檢測它是否再次移動。我可能沒有那個好名字,所以我沒有在谷歌上找到任何東西。 謝謝!jQuery:如何檢測鼠標是否靜止
-3
A
回答
0
As kgdesouz pointed out,here is a simple script using jQuery處理mousemove
和keypress
事件。如果時間到期,頁面被重新加載。
<script type="text/javascript">
idleTime = 0;
$(document).ready(function() {
//Increment the idle time counter every minute.
var idleInterval = setInterval("timerIncrement()", 60000); // 1 minute
//Zero the idle timer on mouse movement.
$(this).mousemove(function (e) {
idleTime = 0;
});
$(this).keypress(function (e) {
idleTime = 0;
});
})
function timerIncrement() {
idleTime = idleTime + 1;
if (idleTime > 19) { // 20 minutes
window.location.reload();
}
}
</script>
+0
非常感謝分享 –
+0
評論部分20分鐘實際上應該是20秒...... – Tzar
相關問題
- 1. 如何檢測鼠標是否爲真?
- 2. WPF - 如何檢測鼠標是否停止移動
- 3. Java swing:如何檢測鼠標何時靜止
- 4. 檢測鼠標是否被拖入AppKit
- 5. 檢測鼠標是否無線
- 6. 如何檢測鼠標光標是否超出元素?
- 7. jQuery - 檢測鼠標是否仍然存在?
- 8. 檢測文本是否在鼠標上突出顯示jQuery
- 9. 檢查DOM是否靜止
- 10. 如何檢測鼠標是否在菜單欄上?
- 11. 如何檢測鼠標是否移動到左側或右側?
- 12. 如何檢測鼠標是否落在可可窗口之外?
- 13. 如何檢測鼠標是否在picturebox中的圖像?
- 14. 如何檢測mouseup被觸發時鼠標是否在移動?
- 15. 檢測鼠標是否接觸地面或是否在空中
- 16. 檢測鼠標停止時間間隔
- 17. 停止重複檢測鼠標
- 18. 檢測與jquery鼠標移動
- 19. jquery檢測第一個鼠標移動
- 20. 用jQuery檢測鼠標方向
- 21. 檢測是否鼠標是多個元素
- 22. 如何檢測鼠標點擊python 3.6.1
- 23. 如何檢測鼠標點擊QLineEdit
- 24. 如何檢測人造鼠標移動?
- 25. 如何檢測鼠標中鍵點擊?
- 26. gmail如何檢測鼠標移動?
- 27. 如何檢測鼠標點擊
- 28. 如何檢測鼠標滾輪傾斜?
- 29. richfaces如何檢測鼠標事件
- 30. 如何在鼠標左鍵按下時檢測鼠標移動?
請提供一些證據表明您研究了該主題。 [查詢](http://stackoverflow.com/questions/667555/detecting-idle-time-in-javascript-elegantly)就會產生你的答案。 – kgdesouz