<div id="test" style="width:50px;height:50px;position:absolute;left:200px;top:200px;background-color:#f00;">look me</div>
<script type="text/javascript">
window.onload = function ()
{
var test = document.getElementById("test"),
i=0,
speed = 1,
style=test.style;
function func()
{
i++;
if( i < 20 )
{
var left = style.left.substr(0,style.left.indexOf("px")),
top = style.top.substr(0,style.top.indexOf("px")),
width = style.width.substr(0,style.width.indexOf("px")),
height = style.height.substr(0,style.height.indexOf("px"));
style.left = +left - speed + "px";
style.top = +top - speed + "px";
style.width = +width + 2*speed + "px";
style.height = +height + 2*speed + "px";
}
else
clearInterval(Timer);
}
var Timer = setInterval(func,100)
}
</script>
温馨提示:答案为网友推荐,仅供参考