<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background-color: black;
}
.box {
position: absolute;
width: 780px;
height: 520px;
padding: 5px;
border: 2px solid white;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
/* 弹性盒子 */
display: flex;
justify-content: space-between;
flex-wrap: wrap;
align-content: space-between;
}
.box .pic1 {
width: 250px;
height: 250px;
}
img {
width: 250px;
height: 250px;
}
</style>
<body>
<div class="box">
<div class="pic1"><img src="img/1.jpg" alt=""></div>
<div class="pic1"><img src="img/2.jpg" alt=""></div>
<div class="pic1"><img src="img/3.jpg" alt=""></div>
<div class="pic1"><img src="img/4.jpg" alt=""></div>
<div class="pic1"><img src="img/5.jpg" alt=""></div>
<div class="pic1"><img src="img/6.jpg" alt=""></div>
</div>
<script>
$(function() {
// hover是鼠标经过和离开的复合事件,第一个function是鼠标经过事件
// 第二个function是鼠标离开事件.
$('.box > div').hover(function() {
$(this).siblings().stop().fadeTo(100, 0.5);
}, function() {
$(this).siblings().stop().fadeTo(100, 1)
})
})
</script>
</body>
成果展示,用jQuery写的就是简单,