你好, 找不到代码:x有人可以发帖,或者解释如何在10分钟的非活动状态后如何进行弹出操作?在10分钟不活动后显示弹出框
当页面加载后,成员是不活跃的10分零成员会得到一些按钮的弹出窗口和文本
<div>
<p>Away from keyboard?</p>
<ul class="button">
<li><a href="#0">I'm Back!</a></li>
</ul>
</div>
你好, 找不到代码:x有人可以发帖,或者解释如何在10分钟的非活动状态后如何进行弹出操作?在10分钟不活动后显示弹出框
当页面加载后,成员是不活跃的10分零成员会得到一些按钮的弹出窗口和文本
<div>
<p>Away from keyboard?</p>
<ul class="button">
<li><a href="#0">I'm Back!</a></li>
</ul>
</div>
var seconds = 0;
var timeoutCounter = setInterval(function(){
seconds++;
if(sec == 600) {
// do stuff to launch popup
clearInterval(timeoutCounter);
}
}, 1000);
$(document).mousemove(function (e) {
clearInterval(timeoutCounter);
seconds = 0;
setInterval(timeoutCounter);
});
$(document).keypress(function (e) {
clearInterval(timeoutCounter);
seconds = 0;
setInterval(timeoutCounter);
});
这基本上运行每一秒 - 如果它是第600秒,它在运行你的代码后退出。
附上事件到对象document
与setTimeout
方法以显示弹出式沿。做到这一点的方法之一是
var popupTimer,
TIME_OUT = 600;
// function that displays the popup
function displayPopup() {
// display the popup here
}
// Set the timeout to display the popup
popupTimer = setTimeout(displayPopup, TIME_OUT);
// attch events to the document object
// you can add more events here based on
// what events you want to track
$(document).on('click change keypress', function() {
// clear the timeout whenever the event is handled
clearTimeout(popupTimer);
// Reset the timer
popupTimer = setTimeout(displayPopup, TIME_OUT);
});
也许尝试此处提供的解决方案http://stackoverflow.com/questions/667555/detecting-idle-time-in-javascript-elegantly –