我将此javascript用作div的倒数计时器,同时检测鼠标闲置。如何在没有鼠标移动的情况下重定向并显示当前计时器的计数
var timer = null;
setInterval(function() {
var div = document.querySelector("#counter");
var count = div.textContent * 1 - 1;
div.textContent = count;
if (count == 0) {
window.location.href="https://example.com";
}
}, 1000);
function goAway() {
clearTimeout(timer);
timer = setTimeout(function() {
window.location.href="https://example.com";
}, 5000);
}
window.addEventListener('mousemove', goAway, true);
goAway();
如果用户超过5秒没有鼠标移动,我希望他被重定向到另一个页面。 example.com在这种情况下。这部分工作。不过,我也打算让一个div的权利显示倒数被重定向,并在.mousemove事件的情况下消失。我似乎无法让他们两人工作。
是否有可能?
请解释一下你的代码是做错了。在我们能够帮助解决问题之前,我们需要知道哪些方面无法解决。 – Soviut