var porssss=document.getElementById("brands_right").getElementsByTagName("p"); for(var i=0;i<porssss.length;i++) { porssss[i].style.top="140px"; porssss[i].parentNode.onmouseover=function(){porssss_show(this,30);} porssss[i].parentNode.onmouseout=function(){porssss_show(this,140);} } function porssss_show(element,number){ if(element.childNodes[1].moveThis){clearTimeout(element.childNodes[1].moveThis);} var pore_top=parseInt(element.childNodes[1].style.top); if(pore_top==number){return;} else if(pore_top>number){pore_top-=10;} else if(pore_top<number){pore_top+=10;} element.childNodes[1].style.top=pore_top+"px"; element.childNodes[1].moveThis=window.setTimeout(function(){porssss_show(element,number);},5 );//element在此为一个对象,可以使用此方法继续调用。 }
效果: