带遮罩效果的图片展示动画:鼠标hover动画显示遮罩和线
->
<div class="img-wrap">
<div class="mask">
<h1>NCT DREAM</h1>
<p>MARK RENJUN HEACHAN JENO JEAMIN CHENLE JISUNG</p>
</div>
<img src="10.jpg" />
</div>
四条线用伪类做
div {
box-sizing: border-box;
}
img {
width: 100%;
}
.img-wrap {
position: relative;
width: 600px;
height: 406px;
margin: 100px auto;
}
.img-wrap .mask {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, .5);
color: #fff;
text-align: center;
padding-top: 150px;
line-height: 100px;
opacity: 0;
transition: opacity .3s;
}
.img-wrap::before,
.img-wrap::after,
.img-wrap .mask::before,
.img-wrap .mask::after {
content: '';
display: block;
position: absolute;
z-index: 1;
transition: all .3s;
}
.img-wrap::before,
.img-wrap::after {
width: 100%;
height: 0;
opacity: 0;
}
.img-wrap .mask::before,
.img-wrap .mask::after {
width: 0;
height: 100%;
}
.img-wrap::before {
border-top: 1px solid #fff;
top: 0;
left: 0;
}
.img-wrap::after {
border-bottom: 1px solid #fff;
bottom: 0;
left: 0;
}
.img-wrap .mask::before {
border-left: 1px solid #fff;
left: 0;
top: 0;
}
.img-wrap .mask::after {
border-right: 1px solid #fff;
right: 0;
top: 0;
}
.img-wrap:hover .mask {
opacity: 1;
}
.img-wrap:hover::before {
opacity: 1;
top: 50px;
}
.img-wrap:hover::after {
opacity: 1;
bottom: 50px;
}
.img-wrap:hover .mask::before {
left: 50px;
}
.img-wrap:hover .mask::after {
right: 50px;
}
盒子聚焦效果:hover火箭旋转,阴影增加,线条聚集
->
四条线从四周起始,从0变为边框长度,向内运动聚焦
<div class="card">
<span class="line left-line"></span>
<span class="line right-line"></span>
<span class="line top-line"></span>
<span class="line bottom-line"></span>
<div class="img-box">
<img src="n.jpg" />
</div>
<div class="content-box">
<h2>NCT</h2>
<h3>Neo Culture Technology</h3>
<p>NCT127 NCTdream WayV</p>
</div>
</div>
body {
background-color: #252a30;
}
div {
box-sizing: border-box;
}
img {
width: 100%;
}
.card {
position: relative;
width: 400px;
height: 200px;
box-shadow: 0 0 3px #b1db56;
margin: 300px auto;
cursor: pointer;
transition: box-shadow .3s;
}
.card div {
float: left;
}
.card .img-box {
width: 200px;
height: 200px;
padding: 35px;
}
.card .img-box img {
transition: transform .3s;
}
.card .content-box {
width: 200px;
height: 200px;
text-align: center;
}
.card .content-box h2,
.card .content-box h3 {
color: #b1db56;
}
.card .content-box p {
color: #ccc;
}
.card .line {
position: absolute;
display: block;
color: #b1db56;
transition: all .3s;
width: 0;
height: 0;
}
/*线从右边进去*/
.card .line.top-line {
top: -1px;
right: -250px;
border-top: 1px solid #b1db56;
}
.card .line.bottom-line {
bottom: -1px;
left: -250px;
border-bottom: 1px solid #b1db56;
}
.card .line.left-line {
left: -1px;
top: -150px;
border-left: 1px solid #b1db56;
}
.card .line.right-line {
right: -1px;
bottom: -150px;
border-right: 1px solid #b1db56;
}
.card:hover {
box-shadow: 0 0 15px #b1db56;
}
.card:hover .img-box img {
transform: rotate(360deg);
}
/*hover的时候线的宽或高恢复成盒子的边框长度*/
.card:hover .line.top-line,
.card:hover .line.bottom-line {
width: 399px;
}
.card:hover .line.left-line,
.card:hover .line.right-line {
height: 199px;
}
/*位置也恢复到边框位置*/
.card:hover .line.top-line {
right: 0;
}
.card:hover .line.bottom-line {
left: 0;
}
.card:hover .line.left-line {
top: 0;
}
.card:hover .line.right-line {
bottom: 0;
}