<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title></title> <style type="text/css"> *{margin: 0;padding: 0;text-align: center;line-height: 100px;} ul,li{list-style: none;} ul li{width: 200px;height: 100px;background: yellow;margin-bottom: 20px;font-size: 12px;color: blue;border: 2Px solid pink;} </style> <script type="text/javascript"> window.onload=function(){ /*var Li=document.getElementsByTagName('li') for(var i=0;i<Li.length;i++){ Li[i].timer=null; Li[i].onmouseover=function(){ star(this,400); } Li[i].onmouseout=function(){ star(this,200); } } }*/ var Li1=document.getElementById('li1'); var Li2=document.getElementById('li2'); var Li3=document.getElementById('li3'); Li1.onmouseover=function(){ star(this,400); } Li1.onmouseout=function(){ star(this,100); } } function getStyle(obj,attr){ if(obj.currentStyle){ return obj.currentStyle[attr]; } else{ return getComputedStyle(obj,false)[attr]; } } var alpha=30; function star(obj,iTarget){ clearInterval(obj.timer); obj.timer=setInterval(function(){ var s=parseInt(getStyle(obj,'height')) var speed=(iTarget-s)/8; speed=speed>0?Math.ceil(speed):Math.floor(speed); if(s==iTarget){ clearInterval(obj.timer); }else{ obj.style.width=s+speed+'px'; } },30) } </script> </head> <body> <ul> <li id='li1'>么么哒</li> <li id='li2'>啦啦啦</li> <li id='li3'>啪啪啪</li> </ul> </body> </html>
已解决,最下面的宽没改成高.......