延时提示框
程序员文章站
2022-05-31 20:26:42
...
代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
#div1{
float: left;
width:50px;
height: 50px;
background-color: red;
}
#div2{
float: left;
margin-left: 30px;
width: 250px;
height: 250px;
background-color: thistle;
display: none;
}
</style>
<script>
window.onload = function(){
var div1 = document.getElementById('div1');
var div2 = document.getElementById('div2');
var timer = null;
div1.onmouseover = function(){
div2.style.display = 'block';
clearTimeout(timer);
}
div1.onmouseout = div2.onmouseout = function(){
timer = setTimeout(function(){
div2.style.display = 'none';
},5000);
}
div2.onmouseover = function(){
div2.style.display = 'block';
clearTimeout(timer);
}
}
</script>
</head>
<body>
<div id="div1"></div>
<div id="div2"></div>
</body>
</html>
效果图:
上一篇: 2188-Frames ZCMU