<div id=myElement style="height:100px;width:100px;background-color:red;">dsa</div><script defer=defer>
var a=function(from,to,x){
return (to-from)*x+from
}
var b=document.getElementById("myElement");setInterval(function(){
b.style.width = a(b.style.width, 500, 0.1)+'px';
})
</script>
var a=function(from,to,x){
return (to-from)*x+from
}
var b=document.getElementById("myElement");setInterval(function(){
b.style.width = a(b.style.width, 500, 0.1)+'px';
})
</script>
<div id=myElement style="height:100px;width:100px;background-color:red;">dsa</div><script defer=defer>
var a=function(from,to,x){
return (to-from)*x+from
}
var b=document.getElementById("myElement");setInterval(function(){
b.style.width = a(b.style.width, 500, 0.1)+'px';
},200)
</script>
可以使用b.style.width = a(b.clientWidth, 500, 0.1)+'px';
<div id=myElement style="height:100px;width:100px;background-color:red;">dsa</div>
<script defer=defer>
var a=function(from,to,x){
window.status= (to-from)*x+from;
return (to-from)*x+from
}
var b=document.getElementById("myElement");
alert(b.style.width);
setInterval(function(){
b.style.width = a(parseInt(b.style.width), 500, 0.1)+'px';
},200)
</script>