<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="Content-type" content="text/html">
<title>动画框架养成记</title>
<style>
*{
padding:0;
margin:0;
}
#frame{
width:400px;
height:200px;
margin:100px auto;
border:1px solid #888;
background: #efefef;
}
#fg{
width:300px;
margin:0px auto;
/*background: #efefef;*/
}
#fg:after{
content:'';
display: table;
clear:both;
}
#fg figure{
float:left;
width:60px;
height: 80px;
font-size: 14px;
background: #ffffff;
margin-right:15px;
margin-bottom: 15px;
padding-left:12px;
border:1px solid #ffffff;
box-sizing:border-box;
position: relative;
overflow: hidden;
}
#fg figure i{
position: absolute;
top:10px;
display:block;
/*border:1px solid ;*/
}
#fg figure figcaption{
/*border:1px solid;*/
position: absolute;
bottom:10px;
left:0;
right:0;
text-align: center
}
#fg figure figcaption a{
text-decoration: none;
color:#444444;
}
#fg figure figcaption a:hover{
color:rgba(255,0,0,0.6);
}
</style>
<script type="text/javascript">
window.onload=function(){
var odiv=document.getElementById('fg');
var fignum=odiv.getElementsByTagName('figure');
var timer=null;
for(var i=0;i<fignum.length;i++){
fignum[i].onmouseover=function(){
var figimg=this.getElementsByTagName('i')[0];
moreover(figimg,{top:-40,opacity:0},function(){
figimg.style.top=20+'px'
moreover(figimg,{top:10,opacity:1000});
});
}
}
function moreover(obj,json,fn){
clearInterval(obj.timer);
var flag=true;//标杆,判断是否所有运动都完成
obj.timer=setInterval(function(){
for(var attr in json){
var cur=0;
if(attr=='opacity'){
cur=Math.round(parseInt(getstyle(obj,attr))*100);
// alert(cur)
}else{
cur=Math.round(parseInt(getstyle(obj,attr)));
}
var speed=(json[attr]-cur)/8;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(json[attr]!=cur){
flag=false;
}
if(attr=='opacity'){
obj.style.filter='alpha(opacity:'+(cur+speed)+')';
obj.style.opacity=(cur+speed)/100;
}else{
obj.style[attr]=cur+speed+"px";
}
}
if(flag){
clearInterval(obj.timer);
if(fn){
fn()
}
}
},20);
}
function getstyle(obj,attr){//获取syle值
if(obj.currentStyle){
return obj.currentStyle[attr];
}else{
return getComputedStyle(obj,false)[attr];
}
}
}
</script>
</head>
<body>
<div id="frame">
<div id="fg">
<figure>
<i><img src="image/airplane.png" alt=""></i>
<figcaption><a href="">图片1</a></figcaption>
</figure>
<figure>
<i><img src="image/briefcase.png" alt=""></i>
<figcaption><a href="">图片2</a></figcaption>
</figure>
<figure>
<i><img src="image/headphones.png" alt=""></i>
<figcaption><a href="">图片3</a></figcaption>
</figure>
<figure>
<i><img src="image/home.png" alt=""></i>
<figcaption><a href="">图片4</a></figcaption>
</figure>
<figure>
<i><img src="image/office.png" alt=""></i>
<figcaption><a href="">图片5</a></figcaption>
</figure>
<figure>
<i><img src="image/newspaper.png" alt=""></i>
<figcaption><a href="">图片6</a></figcaption>
</figure>
<figure>
<i><img src="image/pencil.png" alt=""></i>
<figcaption><a href="">图片7</a></figcaption>
</figure>
<figure>
<i><img src="image/home3.png" alt=""></i>
<figcaption><a href="">图片8</a></figcaption>
</figure>
</div>
</div>
</body>
</html>