2008-12-21 103 views
0

在Javascript中,我希望我的onmouseout事件在生效前三秒鐘內睡眠/暫停/等待/(不確定此處使用的術語是否合適)。這是如何完成的?Javascript onmouseout睡眠?

感謝

+0

我會用這個詞是延遲後執行doSomething功能。 – AnthonyWJones 2008-12-21 21:11:28

回答

3
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); 
} 
+0

您應該將事件對象傳遞給內部匿名函數。 – Triptych 2008-12-21 21:04:50

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

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

什麼上面的代碼確實是onmouseout 3秒被調用