首先先写两个DIV
<div id="kuang" style="400px;"> <div id="se" style="0px;"></div> </div>
写样式
<style type="text/css"> *{ margin:0px auto;} #kuang{ height:50px; border:1px solid #000} #se{ height:50px; background-color:red; float:left;} </style>
现在,在写如何让kuang里面的红色变长。
<script type="text/javascript"> window.setTimeout("Zou()",20); 延迟
也可以用间隔,最后在清一下间隔就行
function Zou() {
var y = document.getElementById("se");
var k = document.getElementById("kuang");
var w = y.style.width;
var kw = k.style.width; var wc = parseInt(w.substr(0,w.length-2)); if(wc<400) { wc =wc+2; y.style.width = wc+"px"; window.setTimeout("Zou()",20); 自己调自己 }
</script>