其他分享
首页 > 其他分享> > js鼠标进入,延迟显示提示框

js鼠标进入,延迟显示提示框

作者:互联网

鼠标进入,延迟显示提示框

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>鼠标进入,延迟显示提示框</title>
        <style>
            .box{
                width: 500px;
                height: 500px;
                border: 1px solid black;
                position: relative;
            }
            #txt{
                display: none;
                width: 200px;
                height: 30px;
                line-height: 30px;
                border: 1px solid pink;
                position: absolute;
                right: 10px;
            }
        </style>
    </head>
    <body>
        <div class="box">
            鼠标进入,延迟显示提示框
        <p id="txt">
            提示框
        </p>
    </div>
    </body>
        <script>
            var obox=document.querySelector(".box");
            var otxt=document.getElementById("txt")
            var t;
            obox.onmouseover=function(){
                clearTimeout(t)
                t = setInterval(function(){
                otxt.style.display="block";
            },500)
            }
            obox.onmouseout = function(){
                clearTimeout(t)
                otxt.style.display="none"
            }
        </script>
    </html>

标签:function,鼠标,otxt,js,height,var,提示框
来源: https://www.cnblogs.com/cupid10/p/12881003.html