getStyle(obj,attr)
为啥我的动画不出来
<style>
*{
margin:0;
padding:0;
}
div{
width:200px;
height:200px;
background:red;
border:4px solid black;
}
</style>
<script>
window.onload=function(){
var odiv=document.getElementById("div1");
alert(odiv.stye.width);
odiv.onmouseover=function(){
startMove();
}
}
var timer=null;
function startMove(){
clearInterval(timer);
var odiv=document.getElementById("div1");
timer=setInterval(function(){
if(odiv.offsetWidth==0){
clearInterval(timer);
}else{
// odiv.style.width=odiv.offsetWidth-9+'px';
odiv.style.width=parseInt(getStyle(odiv,width))-1+'px';
}
},30)}
function getStyle(obj,attr){
if(obj.currentStyle){
return obj.currentStyle[attr];
}else{
return obj.getComputedStyle(obj,false)[attr];
}
}
</script>
</head>
<body>
<div id="div1" ></div>
</body>
</html>