jQuery手风琴
<!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">
<script src="./jQuery/jquery-3.4.1.js"></script> 引入jQuery库
<title>Document</title>
<style>
* {
padding: 0px;
margin: 0px;
list-style: none;
}
.box {
width: 1090px;
height: 430px;
}
.box div {
width: 100px;
height: 430px;
float: left;
position: relative;
overflow: hidden;
}
img {
width: 790px;
height: 430px;
}
p {
width: 38px;
height: 390px;
font-size: 20px;
padding: 20px 31px;
background-color: rgba(0, 0, 0, 0.4);
position: absolute;
top: 0px;
left: 0px;
color: white;
}
.box .show {
width: 790px;
}
</style>
</head>
<body>
<div class="box">
<div class="show">
<img src="./image/p6 (1).jpg" alt="">
<p>图片一</p>
</div>
<div>
<img src="./image/p6 (2).jpg" alt="">
<p>图片2</p>
</div>
<div>
<img src="./image/p6 (3).jpg" alt="">
<p>图片3</p>
</div>
<div>
<img src="./image/p6 (4).jpg" alt="">
<p>图片4</p>
</div>
</div>
<script>
$(function () {
$('div').each(function (x) {
$('div').mouseover(function () { //在jQuery中鼠标事件都没有on
$(this).eq(x).addClass('show').siblings().removeClass();//siblings是所有兄弟节点的意思
})
})
})
</script>
</body>
</html>
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/085475c0a2520b60620b7090433e7127.png)