2008-12-21 97 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秒被调用