move.js代碼如下:function startMove(obj,json,fn){ var flag=true;clearInterval(obj.timer);obj.timer=setInterval(function(){ 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)); } //計(jì)算速度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)+')'; obj.style[attr]=(icur+speed)/100; }else{ obj.style[attr]=icur+speed+'px';}}if(flag){ clearInterval(obj.timer); if(fn){ fn(); }}},30)}function getStyle(obj,attr){ if(obj.currentStyle){ //IE return obj.currentStyle[attr]; }else{ //Firefox return getComputedStyle(obj,false)[attr]; } }主頁面代碼如下:<!DOCTYPE html><html><head><title>taobao</title><meta charset="utf-8"><style>*{ margin:0; padding:0;}#move{ width:600px; margin:10px auto; border:1px solid #ccc; background: #567;}#move a{ display:inline-block; width:70px; height:80px; border:1px solid #ddd; border-radius:3px; background-color: #fff; text-align: center; margin:10px 17px; position: relative; padding-top: 40px; color:#9c9c9c; font-size: 12px; text-decoration: none; line-height: 25px; overflow: hidden;}p{ overflow: hidden; display: inline-block; bottom: 0; position: absolute;}#move a i{ position: absolute; top: 20px; left:0; display: inline-block; width:100%; text-align: center; filter: alpha(opacity:100); opacity: 1;}#move a:hover{ color:#f00;}#move img{ border:none;}</style><script type="text/javascript" src="move.js"></script><script type="text/javascript"> window.onload=function(){ var oMove=document.getElementById('move'); var aList=oMove.getElementsByTagName('a'); for(var i=0;i<aList.length;i++){ aList[i].onmouseover=function(){ var _this=this.getElementsByTagName('i')[0]; startMove(_this,{top:-25,opacity:0},function(){ _this.style.top=30+'px'; startMove(_this,{top:20,opacity:0}); }); } } }</script></head><body><div id="move"><a href="#"><i><img src="images/01.png"></i><p>聯(lián)系人</p></a><a href="#"><i><img src="images/02.png"></i><p>時(shí)間</p></a><a href="#"><i><img src="images/03.png"></i><p>備忘錄</p></a><a href="#"><i><img src="images/04.png"></i><p>檢查</p></a><a href="#"><i><img src="images/05.png"></i><p>家庭</p></a></div></body>
求助:只能出去不能回來,top值只能停在-25,可能是函數(shù)調(diào)用問題,但我不知道在哪里
qq_雨歸木蘭殤_0
2016-09-27 18:24:44