JSFiddle - React, Tailwind, and code Playground
HTML
<div class="main">
Test
</div>
<div id="SecondsUntilExpire"></div>
CSS
.main {
height: 2000px;
width: 100%;
border: 1px solid #000000;
}
JavaScript
var IDLE_TIMEOUT = 10; //seconds
var _idleSecondsCounter = 0;
document.onclick = function() {
_idleSecondsCounter = 0;
};
document.onmousemove = function() {
_idleSecondsCounter = 0;
};
document.onkeypress = function() {
_idleSecondsCounter = 0;
};
window.setInterval(CheckIdleTime, 1000);
function CheckIdleTime() {
_idleSecondsCounter++;
var oPanel = document.getElementById("SecondsUntilExpire");
if (oPanel)
oPanel.innerHTML = (IDLE_TIMEOUT - _idleSecondsCounter) + "";
if (_idleSecondsCounter >= IDLE_TIMEOUT) {
$(window).scrollTop(0);
$('html, body').animate({scrollTop: 1000}, 800);
}
}