javascript - 如何设置鼠标悬停显示延迟

标签 javascript delay detection onmouseover

我在表格列表上使用鼠标悬停效果以在悬停时显示类(class)内容。 然而,由于它在表格中,当从一行到另一行时,它“变化太快”,这就是为什么我想对鼠标悬停效果进行一些延迟。

我的代码目前看起来像这样:

onmouseover="show('id')" onmouseout="hide('id')">

如何做一个小延迟?

最佳答案

一个非jQuery的解决方案,供引用:

<script>

    var show=function(x)
    {
        setTimeout(
            function()
            {
                do the stuff...
            },
            200
        );
    };

    var hide=function(x)
    {
        setTimeout(
            function()
            {
                do the other stuff...
            },
            200
        );
    };

</script>
<div onmouseover="show('id')"  onmouseout="show('id')"></div>

基本上,我定义了 showhide 作为创建匿名函数的函数,这些函数执行实际的显示和隐藏,然后在 200 毫秒延迟后使用 设置超时

关于javascript - 如何设置鼠标悬停显示延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23240612/

相关文章:

javascript - AngularJS - 尝试信任需要字符串 : Context: html 的内容中的非字符串值

抛出 ConnectException 之前的 Java 延迟

Paypal 延迟链式付款返回 "Internal server error. Please check the server logs for details1"

algorithm - 如何检测图像纹理?

web - 如何检测用户在网站上使用的是 Mac 还是 Windows

javascript - 我可以从 canvas 元素获取图像并在 img src 标签中使用它吗?

javascript - 将文本保留在 div : Both newline, 空白和长单词内

javascript - 我创建的类不导出对象

java - 在java中每2秒重复一次 Action

javascript - 如何根据 HTTP 主机名 header onload 进行 Javascript 重定向?