<!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>動畫框架養(yǎng)成記</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>
2015-12-12
把var?flag=true; ?放到下面我給放那個位置
for(var?attr?in?json){
var?cur=0;
var?flag=true; ? // 放到這里
if(attr=='opacity'){
cur=Math.round(parseInt(getstyle(obj,attr))*100);
//?alert(cur)
}else{
cur=Math.round(parseInt(getstyle(obj,attr)));
}
2016-04-10
改完之后,透明度回不到1了,有沒有大神能給我解釋一下啊啊。
2015-12-29
如果放到外面就一直為真了啊
2015-12-12
把那個 ?flag 標志 放到function函數(shù)里面 ?你試下 看看
2015-12-12
你的運行時是什么問題