Javascript onmouseout Sleep?

In Javascript, I want my onmouseout event to sleep / pause / wait / (not sure about the correct terminology here) for three seconds before taking effect. How is this achieved?

thank

0


source to share


2 answers


function outfunction(event) {
    var that = this; // to be able to use this later.
    window.setTimeout(function() {
    /* you can use 'that' here to refer to the element
       event is also available in this scope */
    }, 3000);
}

      



+3


source


var doSomething = function () {
    //Some code will here after 3 seconds of mouseout
};

anElement.onmouseout = function () {
   setTimeout(doSomething, 3000);
};

      



What the above code does is execute the function doSomething

after 3 seconds of callingonmouseout

+1


source







All Articles