您的位置:首页 > Web前端 > JavaScript

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

2014-06-01 20:25 549 查看
<!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>


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: