利用css动画实现图片渐入的功能
实现效果
点击文字实现相应的效果
代码实现
<!DOCTYPE html>
<html>
<head>
<title> 图片渐入效果的实现 </title>
<meta charset="utf-8"/>
<style>
a{
display:inline-block;
width:100px;
height:20px;
color:#e4393c;
background:pink;
text-align:center;
position:relative;
z-index:20;
}
#d1{
width:430px;
margin:20px auto;
}
#d2{
width:350px;
height:350px;
padding:15px;
border:1px solid #ddd;
margin-top:30px;
position:relative;
z-index:9;
margin:0px auto;
}
img{
display:none;
position:absolute;
}
@keyframes img1{
from{
transform:translate(-350px);
}
to{
transform:translate(0px);
}
}
@-webkit-keyframes img1{
from{
transform:translate(-350px);
}
to{
transform:translate(0px);
}
}
#img1:target{
display:block;
z-index:10;
animation:img1 5s linear;
-webkit-animation:img1 5s linear;
-webkit-animation-fill-mode:forwards;
}
@keyframes img2{
from{
transform:translate(0px,350px);
}
to{
transform:translate(0px,0px);
}
}
@-webkit-keyframes img2{
from{
transform:translate(0px,350px);
}
to{
transform:translate(0px,0px);
}
}
#img2:target{
display:block;
z-index:11;
animation:img2 5s linear;
-webkit-animation:img2 5s linear;
-webkit-animation-fill-mode:forwards;
}
@keyframes img3{
from{
transform:scale(0.1);
}
to{
transform:scale(1);
}
}
@-webkit-keyframes img3{
from{
transform:scale(0.1);
}
to{
transform:scale(1);
}
}
#img3:target{
display:block;
z-index:12;
animation:img3 5s linear;
-webkit-animation:img3 5s linear;
-webkit-animation-fill-mode:forwards;
}
@keyframes img4{
from{
transform:scale(0.1) rotate(0deg);
}
to{
transform:scale(1) rotate(720deg);
}
}
@-webkit-keyframes img4{
from{
transform:scale(0.1) rotate(0deg);
}
to{
transform:scale(1) rotate(720deg);
}
}
#img4:target{
display:block;
z-index:13;
animation:img4 5s linear;
-webkit-animation:img4 5s linear;
-webkit-animation-fill-mode:forwards;
}
</style>
</head>
<body>
<div id="d1">
<a href="#img1">左移进入</a>
<a href="#img2">上移进入</a>
<a href="#img3">放大进入</a>
<a href="#img4">放大旋转进入</a>
</div>
<div id="d2">
<img src="a.png" id ="img1" />
<img src="b.png" id ="img2" />
<img src="c.png" id ="img3" />
<img src="d.png" id ="img4" />
</div>
</body>
</html>