<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
#box{width:100px;height:100px;background:pink;}
#big{width:200px;height:200px;background:blue;display:none;margin-left:800px;}
</style>
</head>
<body>
<div id="box"></div>
<div id="big"></div>
</body>
<script>
var box = document.getElementById('box');
var big = document.getElementById('big');
var timmer;
box.onmouseover = big.onmouseover = function (){
// console.log('鼠标移入')
// box.style.background="yellow";
clearTimeout(timmer);
big.style.display="block";
}
box.onmouseout = big.onmouseout = function(){
// console.log('鼠标移除')
// box.style.background="pink";
timmer=setTimeout(function(){
big.style.display="none";
},300);
}
// big.onmouseover = function(){
// big.style.display="block";
// }
// big.onmouseout = function(){
// big.style.display="none";
// }
</script>
</html>点击 "运行实例" 按钮查看在线实例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
#parent{width:300px;height:300px;background:red;}
#son{width:100px;height:100px;background:yellow;}
</style>
</head>
<body>
<div id="parent">
<div id="son"></div>
</div>
</body>
<script>
var parent = document.getElementById('parent');
parent.onmouseenter= function(){
console.log('鼠标移入区域')
}
parent.onmouseleave = function(){
console.log('鼠标移除区域')
}
</script>
</html>点击 "运行实例" 按钮查看在线实例
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号