【发布时间】:2011-10-08 03:28:07
【问题描述】:
我正在使用 Paul Irish 的空闲计时器插件:http://paulirish.com/2009/jquery-idletimer-plugin/。
我想在 5 秒不活动后隐藏一些 div,并在捕捉到用户活动时将它们显示回来。
这是我的代码:
$(document).ready(function(){
$.idleTimer(5000);
$(document).bind("idle.idleTimer", function(){
$("#audio_container").fadeOut(1000);
$(".breadcrumb").fadeOut(1000);
});
$(document).bind("active.idleTimer", function(){
$("#audio_container").fadeIn(1000);
$(".breadcrumb").fadeIn(1000);
});
});
它在 Firefox / Safari / Mobile Safari 上完美运行,但我无法让它在 Chrome 或 IE 8 / 9 上运行。 显然,onmousemove 事件是问题所在,如果我取消绑定 onmousemove 事件,它可以工作(但我需要它,所以这对我来说不是一个可接受的解决方案)。
你可以在这里找到一个例子:
最好的问候,
编辑:
mousemouve 事件位于 idle-timer 插件中。
$.idleTimer = function(newTimeout, elem){
// defaults that are to be stored as instance props on the elem
var idle = false, //indicates if the user is idle
enabled = true, //indicates if the idle timer is enabled
timeout = 30000, //the amount of time (ms) before the user is considered idle
events = 'mousemove keydown DOMMouseScroll mousewheel mousedown touchstart touchmove'; // activity is one of these events
如果我从插件中删除 mousemove 事件,它会起作用。
【问题讨论】:
-
“显然 onmousemove 事件是问题所在” - 但您没有包含那部分代码
-
抱歉,实际上我正在加载空闲计时器插件。在插件中,有如下代码:
codeevents = 'mousemove keydown DOMMouseScroll mousewheel mousedown touchstart touchmove';code -
@citizen con : 谢谢你的帮助,我已经编辑了主帖
-
对不起,我一定很困惑,但它在 Chrome 中对我有用。 IE8 实际上每次都崩溃。
-
还有一点,在 Chrome 和 IE 上,如果鼠标指针不在窗口顶部,则 div 会淡出。
标签: jquery jquery-plugins onmousemove idle-timer