Javascript onmouseout睡觉?

时间:2008-12-21 20:57:16

标签: javascript onmouseout

在Javascript中,我希望我的onmouseout事件在生效前三秒钟进入睡眠/暂停/等待/(不确定这里的正确术语)。这是如何完成的?

感谢

2 个答案:

答案 0 :(得分: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);
}

答案 1 :(得分:1)

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

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

以上代码的作用是在调用doSomething 3秒后执行onmouseout函数