问题描述
我正在写一个带有while循环的脚本。我怎么能让它变得更慢
这样它似乎不会一下子发生 - 所以它看起来好像是动画 - b $ b动画 - 基本上。我在
循环的最后一行尝试了setTimeout(500),但这只是搞砸了。任何帮助将不胜感激 - 谢谢。
I''m writing a script with a while loop in it. How can I get it to go slower
so that it doesn''t appear to happen all at once--so that it looks
animated--basically. I tried the setTimeout(500) in the last line of the
loop, but that just messes things up. Any help would be appreciated--thanks.
推荐答案
赞赏 - 谢谢。
这就是我正在做的事情:
< html>
< head>
< script type =" text / JavaScript">
function growbluebox(widthto, heightto){
var idofbluebox = document.getElementById(" bluebox")
var idofbluebox = document.getElementById(" bluebox")
var blueboxwidthnum = parseInt(idofbluebox.style.width)
var blueboxheightnum = parseInt(idofbluebox.style.height)
while(blueboxwidthnum) < widthto){
blueboxwidthnum = parseInt(idofbluebox.style.width)+ 1;
idofbluebox.style.width = blueboxwidthnum +" px" ;;
}
}
< / script>
< / head>
< body>
< a href ="#" onClick =" growbluebox(500,400)>>增长200宽和200高< / a>
< div id =" bluebox"风格= QUOT;位置:绝对的;左:189px;上:96px;
宽度:228px;高度:129px;的z-index:1; background-color:#99CCFF;
layer-background-color:#99CCFF; border:1px none#000000;">< / div>
< / body>
< / html>
我正试着让盒子慢慢长大,看起来很动画。我还没有得到
到了身高部分。顺便说一下,有没有办法在宽度的同时在
处做高度?谢谢。
appreciated--thanks.
here is what I''m doing:
<html>
<head>
<script type="text/JavaScript">
function growbluebox(widthto,heightto) {
var idofbluebox = document.getElementById("bluebox")
var idofbluebox = document.getElementById("bluebox")
var blueboxwidthnum = parseInt(idofbluebox.style.width)
var blueboxheightnum = parseInt(idofbluebox.style.height)
while (blueboxwidthnum < widthto) {
blueboxwidthnum = parseInt(idofbluebox.style.width) + 1;
idofbluebox.style.width = blueboxwidthnum + "px";
}
}
</script>
</head>
<body>
<a href="#" onClick="growbluebox(500,400)">grow by 200 wide and 200 high</a>
<div id="bluebox" style="position:absolute; left:189px; top:96px;
width:228px; height:129px; z-index:1; background-color: #99CCFF;
layer-background-color: #99CCFF; border: 1px none #000000;"></div>
</body>
</html>
I''m trying to have the box grow slowly so it looks animated. I didn''t get
around to the height part yet. BTW, is there a way I can do the height at
the same time as the width? Thanks.
赞赏 - 谢谢。
这就是我正在做的事情:
< html>
< head>
< script type =" text / JavaScript">
function growbluebox(widthto,heightto){
var idofbluebox = document.getElementById(" bluebox")
var idofbluebox = document.getElementById(" bluebox")
var blueboxwidthnum = parseInt(idofbluebox.style.width)
var blueboxheightnum = parseInt(idofbluebox.style.height) blueboxwidthnum = parseInt(idofbluebox.style.width)+ 1;
idofbluebox.style.width = blueboxwidthnum +" px" ;;
}
< / script>
< / head>
< body>
< a href =" #" onClick =" growbluebox(500,400)>>增长200宽和200
appreciated--thanks.
here is what I''m doing:
<html>
<head>
<script type="text/JavaScript">
function growbluebox(widthto,heightto) {
var idofbluebox = document.getElementById("bluebox")
var idofbluebox = document.getElementById("bluebox")
var blueboxwidthnum = parseInt(idofbluebox.style.width)
var blueboxheightnum = parseInt(idofbluebox.style.height)
while (blueboxwidthnum < widthto) {
blueboxwidthnum = parseInt(idofbluebox.style.width) + 1;
idofbluebox.style.width = blueboxwidthnum + "px";
}
}
</script>
</head>
<body>
<a href="#" onClick="growbluebox(500,400)">grow by 200 wide and 200
高< / a> < div id =" bluebox"风格= QUOT;位置:绝对的;左:189px;上:96px;
宽度:228px;高度:129px;的z-index:1; background-color:#99CCFF;
layer-background-color:#99CCFF; border:1px none#000000;">< / div>
< / body>
< / html>
我正在努力盒子慢慢长大,看起来很动画。我还没到达高度部分。顺便说一句,有没有办法可以在宽度的同时做高度?谢谢。
high</a> <div id="bluebox" style="position:absolute; left:189px; top:96px;
width:228px; height:129px; z-index:1; background-color: #99CCFF;
layer-background-color: #99CCFF; border: 1px none #000000;"></div>
</body>
</html>
I''m trying to have the box grow slowly so it looks animated. I didn''t get
around to the height part yet. BTW, is there a way I can do the height at
the same time as the width? Thanks.
这篇关于放慢循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!