Given that: we should better check if it actually removes the event (on jsfiddle I have doubts currently)
Could something like this fit?
html:
<div>
<p id="checks">
Waiting action
</p>
</div>
<div id="scroller">
In my scenario, I have a mouse event. Where when I scroll the mouse everything it hits a function and respective function executes. I'm looking to check the execution time of the function and when If the execution time of the function exceeds a certain time, I want to stop the function. Is that possible without using setInterval/ setTimeOut!
In my scenario, I have a mouse event. Where when I scroll the mouse everything it hits a function and respective function executes. I'm looking to check the execution time of the function and when If the execution time of the function exceeds a certain time, I want to stop the function. Is that possible without using setInterval/ setTimeOut!
In my scenario, I have a mouse event. Where when I scroll the mouse everything it hits a function and respective function executes. I'm looking to check the execution time of the function and when If the execution time of the function exceeds a certain time, I want to stop the function. Is that possible without using setInterval/ setTimeOut!
In my scenario, I have a mouse event. Where when I scroll the mouse everything it hits a function and respective function executes. I'm looking to check the execution time of the function and when If the execution time of the function exceeds a certain time, I want to stop the function. Is that possible without using setInterval/ setTimeOut!
In my scenario, I have a mouse event. Where when I scroll the mouse everything it hits a function and respective function executes. I'm looking to check the execution time of the function and when If the execution time of the function exceeds a certain time, I want to stop the function. Is that possible without using setInterval/ setTimeOut!
</div>
Js:
var checks = document.getElementById('checks');
var scroller = document.getElementById('scroller');
scroller.addEventListener("scroll", () => {
checks.innerHTML = "on scrolling";
var scrolltimer = setInterval(myTimer, 1000);
function myTimer()
{
checks.innerHTML = "stopping...";
stopwork(scrolltimer,scroller);
}
},true);
function stopwork(scrolltimer,scroller)
{
scroller.removeEventListener("scroll", null);
clearTimeout(scrolltimer);
checks.innerHTML = "stopped";
return false;
}