实现代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
a {
text-decoration: none;
}
li {
list-style:none;
}
.play {
display: block;
width: 130px;
height: 40px;
background-color: pink;
line-height: 40px;
text-align: center;
color: red;
}
.nav {
display: none;
width: 130px;
height: 220px;
background-color: skyblue;
}
.nav ul li {
height: 130px;
height: 55px;
text-align: center;
line-height: 40px;
}
</style>
</head>
<body>
<a href="" class="play">游戏</a>
<div class="nav">
<ul>
<li><a href=''>英雄联盟</a></li>
<li><a href=''>火影忍者</a></li>
<li><a href=''>绝地求生</a></li>
<li><a href=''>反恐精英</a></li>
</ul>
</div>
<script>
var a = document.querySelector('a')
var div = document.querySelector('div')
a.onmouseover = function(){
div.style.display='block';
}
a.onmouseout = function(){
div.style.display='none';
}
div.onmouseover = function(){
div.style.display='block';
}
div.onmouseout = function(){
div.style.display='none';
}
</script>
</body>
</html>
代码运行后:
当鼠标经过时:
当鼠标离开后: