Javascript实现两张图片的延迟加载

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <style type="text/css">
        div
        {
            float: left;
            margin: 10px;
        }

        #div1
        {
            width: 90px;
            height: 50px;
            background-color: red;
        }

        #div2
        {
            width: 250px;
            height: 200px;
            background-color: grey;
            display: none;
        }
    </style>
    <script type="text/javascript">
        window.onload = function () {
            var oDiv1 = document.getElementById('div1');
            var oDiv2 = document.getElementById('div2');


            oDiv1.onmouseover = function () {
                setTimeout(function () {
                    oDiv2.style.display = "block";
                }, 100);

            };
            var a
            oDiv1.onmouseout = function () {
                a = setTimeout(function () {
                    oDiv2.style.display = "none";
                }, 1000);

            };

            oDiv2.onmouseover = function () {
                clearTimeout(a);
            }
            oDiv2.onmouseout = function () {
                setTimeout(function () {
                    oDiv2.style.display = "none";
                }, 100);
            }
        }
    </script>
</head>
<body>
    <div id="div1"></div>
        
    <div id="div2"></div>
</body>
</html>

  

posted @ 2014-06-01 20:25  ICupid  阅读(179)  评论(0编辑  收藏  举报