首页 > 代码库 > 延时提示框

延时提示框

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>qq_info</title>
    <style type="text/css">
        #div1{width:200px;height: 30px;background: red;}
        #div2{width:150px;height:20px;background: #ccc;margin:10px;display: none;}
    </style>
    <script type="text/javascript">
        // ____________001_______________________
        window.onload=function(){
            var oDiv1=document.getElementById(div1);
            var oDiv2=document.getElementById(div2);
            var timer=null;

            oDiv1.onmouseover=function(){
                oDiv2.style.display=block;
                clearTimeout(timer);
            }

            oDiv1.onmouseout=function(){
                timer=setTimeout(function(){
                oDiv2.style.display=none;
                },300);
            }

            oDiv2.onmouseover=function(){
                clearTimeout(timer);
            }
            oDiv2.onmouseout=function(){

                timer=setTimeout(function(){
                oDiv2.style.display=none;
                },300);
            }
        }
    // _____________________001end________________________
    // _____________________002___________________________
        window.onload=function(){
                var oDiv1=document.getElementById(div1);
                var oDiv2=document.getElementById(div2);
                var timer=null;

                function show(){
                    oDiv2.style.display=block;
                    clearTimeout(timer);                    
                }

                function hide(){
                    timer=setTimeout(function(){
                    oDiv2.style.display=none;
                    },300);
                }

                oDiv1.onmouseover=show;
                oDiv2.onmouseover=show;
                oDiv1.onmouseout=hide;
                oDiv2.onmouseout=hide;//注意js函数调用不加括号表示调用的函数整体,加括号表示调用函数返回的值
            }
    //_____________________002end_________________________
    //_____________________003____________________________

        window.onload=function(){
                var oDiv1=document.getElementById(div1);
                var oDiv2=document.getElementById(div2);
                var timer=null;

                oDiv1.onmouseover=oDiv2.onmouseover=function(){
                    oDiv2.style.display=block;
                    clearTimeout(timer);                    
                }

                oDiv1.onmouseout=oDiv2.onmouseout=function(){
                    timer=setTimeout(function(){
                    oDiv2.style.display=none;
                    },300);
                }

            }    
    //_____________________003end_________________________
    </script>
</head>
<body>
    <div id="div1"></div>
    <div id="div2"></div>
</body>
</html>

 

查看范例

延时提示框