使用来自https://github.com/thorst/jquery-idletimer的可爱的 Jquery idletimer :似乎我无法将空闲计时器附加到特定元素(而不是整个文档)。这是我非常简单的代码:
要触发空闲计时器:
$("#testme" ).on( "idle.idleTimer", function(event, elem, obj){ $("#test").html("now idle");});
$( "#testme" ).on( "active.idleTimer", function(event, elem, obj, triggerevent){ $("#test").html("not idle");});
$( "#testme" ).idleTimer(3000);
要在文档中调用它:
<div id="testme" style="border: solid;"><p id="test">I am idle</p></div>
事情就是这样。如果我用 $(document) 替换 $("#testme" ) 它工作正常。但不是当它附加到 div 元素时。我正在使用 jquery-1.11.0.js、jquery.mobile-1.4.2 和 idle-timer.js。
更新:我现在在http://jsfiddle.net/peterrr73/C3w7f/有一个 jsFiddle,它显示了这个半工作,附加到一个元素。正如小提琴所示:空闲的火;然后主动火灾 - 但由于某种原因它停止了。感谢 Jeromy French 对 jsFiddle 的帮助;他在http://jsfiddle.net/jhfrench/2aGL4/12/上处理了整个文档,但不是一个元素。