1<style type="Text/css">2 Div {3 width:100px;4 height:50px;5 background:red;6 margin:10px;7 }8</style>9<body>Ten<div></div> One<div></div> A<div></div> -</body> -<script type="Text/javascript"> theWindow.onload =function () { - varAdiv = document.getElementsByTagName ('Div'); - for(vari =0; i < adiv.length; i++) { -Adiv[i].timer=NULL; +Adiv[i].onmouseover =function () { -Startmove ( This, -); + }; AAdiv[i].onmouseout =function () { atStartmove ( This, -); - }; - } - } - - function Startmove (obj, itarget) { in clearinterval (obj.timer); -Obj.timer =setinterval (function () { to varSpeed = (itarget-obj.offsetwidth)/ -; +Speed = speed >0?Math.ceil (Speed): Math.floor (speed); - if(Obj.offsetwidth = =itarget) { the clearinterval (obj.timer); *}Else { $Obj.style.width = obj.offsetwidth + speed +'px';Panax Notoginseng } -},1); the } +</script>
JavaScript Timer for Animated effects