我已經編寫了一些代碼,可以爲用戶提供一條消息,讓他們忽略該消息,或者如果他們閒置超過一分鐘,則轉到其他頁面。一切正常,除非用戶忽略消息。這裏是我的代碼:用戶閒置後彈出
if (valid) {
var idleTime = 0;
jQuery(document).ready(function() {
var idleInterval = setInterval(timerIncrement, 60000);
});
function resetTimer() {
idleTime = 0;
}
jQuery(document)
.on('mousemove', resetTimer)
.on('keydown', resetTimer)
.on('scroll', resetTimer);
function timerIncrement() {
idleTime = idleTime + 1;
if (idleTime >= 1) {
jQuery('#popup').show();
}
jQuery(window).unbind();
}
jQuery('#popupClose').click(function() {
jQuery('#popup').hide();
});
}
我希望彈出窗口在他們單擊#popupClose後不重新填充。
你只是問在用戶點擊那個元素時如何使用'clearInterval()'? – David
工作小提琴/ plunkr會很好 – Pavan
clearInterval(idleInterval);這將刪除間隔,所以它不會再發生 – schylake