JSFiddle - React, Tailwind, and code Playground
HTML
<div style="width: 100px; height: 100px; background: red;">Hover over me</div>
<p>Don't forget to open your console before testing this!</p>
JavaScript
var foo = new Object();
foo.bar = function() {
// Do something and when complete...
console.log("bar")
a = setTimeout(foo.bar, 3000);
}
$(function(){
a = setTimeout(foo.bar, 3000);
$('div').hover(function(){
// var timeRemaining = (THE TIME REMAINING IN a)
clearTimeout(a);
}, function(){
// a = setTimeout(foo.bar, timeRemaining);
a = setTimeout(foo.bar, 3000);
})
})