求助 這一節(jié)動(dòng)畫最后透明度變成0.88了,沒(méi)有變回1,求大神幫助看看
<!DOCTYPE?html?PUBLIC?"-//W3C//DTD?XHTML?1.0?Transitional//EN"?"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html?xmlns="http://www.w3.org/1999/xhtml"> <head> <meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/> <title>無(wú)標(biāo)題文檔</title> <style?type="text/css"> *{margin:0;padding:0;} span{left:32px;top:20px;position:absolute;opacity:1;filter:alpha(opacity:100);} img{width:40px;height:40px;} a{float:left;display:block;height:100px;width:100px;border:1px?solid?#CCC;font-family:"微軟雅黑";font-size:14px;color:#999;text-align:center;margin:10px;position:relative;text-decoration:none;} a:hover{color:#060;} p{top:60px;left:36px;position:absolute;} </style> <script?src="newmove.js"></script> <script> window.onload=function(){ var?ai=document.getElementsByTagName("a"); for(var?i=0;i<ai.length;i++){ ai[i].onmouseover=function(){ var?This=this; var?span=This.getElementsByTagName('span')[0]; startMove(span,{top:-25,opacity:0},function(){span.style.top=40+"px";startMove(span,{top:20,opacity:100})} ); } } } </script> </head> <body> <a?href=""><span><img?src="1_1.png"?/></span><p>網(wǎng)絡(luò)</p></a> <a?href=""><span><img?src="1_2.jpg"?/></span><p>娛樂(lè)</p></a> <a?href=""><span><img?src="1_3.jpg"?/></span><p>酒店</p></a> </body> </html>
運(yùn)動(dòng)框架代碼如下
function?getStyle(obj,attr){ if(obj.currentStyle){ //IE return?obj.currentStyle[attr]; }?else?{ return?getComputedStyle(obj,false)[attr]; } } //json?=?{attr1:iTarget1,attr2:iTarget2} function?startMove(obj,json,fn){ clearInterval(obj.timer); obj.timer?=?setInterval(function(){ var?flag?=?true;?//標(biāo)志所有運(yùn)動(dòng)是否到達(dá)目標(biāo)值 for(var?attr?in?json){ //取當(dāng)前值 var?icur?=?0; if(attr?==?'opacity'){ icur?=?Math.round(parseFloat(getStyle(obj,attr))*100); }?else?{ icur?=?parseInt(getStyle(obj,attr)); } //求速度 var?speed?=?(json[attr]-icur)/8; speed?=?speed?>?0???Math.ceil(speed)?:?Math.floor(speed); if(icur?!=?json[attr]){ flag?=?false; }? if(attr?==?'opacity'){ obj.style.filter?=?'alpha(opacity:'+(icur+speed)+')';?//IE obj.style.opacity?=?(icur+speed)/100;? }?else?{ obj.style[attr]?=?icur?+?speed?+'px'; } if(flag)?{ clearInterval(obj.timer); flag?=?true; if(fn){ fn(); } } } },20); }//?JavaScript?Document
2016-05-16
后來(lái)檢查了框架 , 我把 if(flag) 寫在了 for in 里邊,這個(gè)是需要寫在fon in括號(hào)外的
2016-05-16
同樣出現(xiàn)了透明度不到1的問(wèn)題
2016-05-15
你的運(yùn)動(dòng)框架有問(wèn)題,用我寫的運(yùn)動(dòng)框架就可以實(shí)現(xiàn)opacity=1;你把下面
if(flag)
flag=ture;//這行刪了試試