<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
body {
background-color: #ccc;
}
.box {
width: 700px;
height: 300px;
background-color: #fff;
margin: 100px auto;
padding: 20px;
}
.box ul {
list-style: none;
display: flex;
flex-wrap: wrap;
}
.box ul li {
box-sizing: border-box;
position: relative;
border: 1px solid #ccc;
width: 350px;
height: 150px;
}
.box ul li a {
color: #000;
}
.box ul li img {
position: absolute;
left: 20px;
top: 20px;
transition: all 1s;
}
.box ul li p {
position: absolute;
right: 20px;
top: 60px;
transition: all 1s;
}
.box li.active {
border-color: aqua;
}
.box li.active img {
left: 60px;
}
.box li.active p {
right: 50px;
}
</style>
</head>
<body>
<div class="box">
<ul>
<li >
<a href="#">
<img src="https://img0.baidu.com/it/u=2892901746,3942342212&fm=253&fmt=auto&app=138&f=PNG?w=126&h=129" alt="">
<p>学科介绍</p>
</a>
</li>
<li>
<a href="#">
<img src="https://img0.baidu.com/it/u=2892901746,3942342212&fm=253&fmt=auto&app=138&f=PNG?w=126&h=129" alt="">
<p>就业前景</p>
</a>
</li>
<li>
<a href="#">
<img src="https://img0.baidu.com/it/u=2892901746,3942342212&fm=253&fmt=auto&app=138&f=PNG?w=126&h=129" alt="">
<p>课程大纲</p>
</a>
</li>
<li>
<a href="#">
<img src="https://img0.baidu.com/it/u=2892901746,3942342212&fm=253&fmt=auto&app=138&f=PNG?w=126&h=129" alt="">
<p>师资介绍</p>
</a>
</li>
</ul>
</div>
<script>
// 1.获取所有的li标签
const lis = document.querySelectorAll('.box ul li')
// 2.设置鼠标经过的状态
for(let i=0;i<lis.length;i++){
lis[i].addEventListener('mouseenter',function(){
lis[i].classList.remove('active')
lis[i].classList.add('active')
})
// 3.设置鼠标移出的状态
lis[i].addEventListener('mouseleave',function(){
lis[i].classList.remove('active')
})
}
// 3.设置鼠标移出的状态
</script>
</body>
</html>
鼠标经过缩近
最新推荐文章于 2024-10-19 18:17:00 发布