You can't delay the firing of the event, but you can delay your handling of the event.
Here's a quick example without jQuery or Prototype that will make it easier to understand.
var delay = function (elem, callback) {
var timeout = null;
elem.onmouseover = function() {
// Set timeout to be a timer which will invoke callback after 1s
timeout = setTimeout(callback, 1000);
};
elem.onmouseout = function() {
// Clear any timers set to timeout
clearTimeout(timeout);
}
};
delay(document.getElementById('someelem'), function() {
alert("Fired");
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…