没有出来动画
这是我写的代码:
<style>
*{
margin:0;
padding:0;
}
#did{
width:200px;
height:200px;
background:red;
top:0px;
}
</style>
<script type='text/JavaScript'>
window.onload=function(){
var oDiv=document.getElementById("did");
oDiv.onmouseover=function(){
startMove(400);
}
}
var timer=null;
function startMove(object){
clearInterval(timer);
timer=setInterval(function(){
var speed=0;
if(oDiv.offsetWidth>object){
speed=-10;
}
else{
speed=10;
}
if(oDiv.offsetWidth==object){
clearInterval(timer);
}
else{
oDiv.style.width=oDiv.offsetWidth+speed;
}
},30)
}
</script>