放慢循环 [英] slowing down a loop

查看:56
本文介绍了放慢循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个带有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.

推荐答案



" TheKeith" < no@spam.com>在留言中写道

news:6c ******************** @ giganews.com ...

"TheKeith" <no@spam.com> wrote in message
news:6c********************@giganews.com...
I我正在写一个带有while循环的脚本。我怎么能让它慢慢地变成
,这样它似乎不会一下子发生 - 所以看起来它看起来很动画 - 基本上。我在
循环的最后一行尝试了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



赞赏 - 谢谢。

这就是我正在做的事情:


< 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.


ciao


你不能放慢循环:循环意味着越快越好。

使用setInterval:在手册中查看它的文档,应该在

窗口对象下。我的意思是,现在这里打印的setInterval

如何工作的完整描述可能需要15分钟。我希望

指向你的方法就足够了。

循环不能减慢,不能用javaScript而不能用其他语言。

还有几种语言所具有的睡眠功能并不意味着要使b / b $ b循环缓慢,而是推迟执行代码块 - 但这是'b
服务器端,就像flush()方法一样说。

ciao

Alberto Vallini

ciao

嗯,为什么不同时使用两者?我的意思是做旧事情的老方法不会老化:

document.images集合是一个有用的工具:它授予你选项

循环遍及所有已安排阵列的可用图像。

否则你必须自己安排,要么通过反复调用document.getElementById(''来修补一个集合

image101'')或

document.getElementsByTagName(" A")

前者非常不实用,第二种比使用
$慢得多b $ b一个已经在加载文档的内置数组中的对象。

这不是纯粹主义者与现代人的问题:这是我在暗示:使用

both - 因为他们添加id功能而忽略这个名字并不是
意味着你必须放弃用
$ b $扫描你所有图像的可能性b alrerady可用的收藏。同样,name =不被弃用。

当然,请随意驳回我的建议,但请注意:这不是建议旧学校的建议。 vs新学校:这是一个建议,

每个人都有可能借给你。

当然,最终会按你的喜好行事。但是使用两个武器而不是

一个更好 - 我们没有放弃步枪因为我们有飞毛腿。

ciao


Alberto
http://www.unitedscripters.com/


" TheKeith" < no@spam.com> ha scritto nel messaggio

新闻:X9 ******************** @ giganews.com ...
ciao

you cannot slow down a loop: loops are meant to be the faster the better.
use setInterval : see on a manual the documentation for it, should be under
the window object. I mean that now a full description of how setInterval
works printed right here would require maybe 15 minutes. I hope having
pointed to you the method will suffice.
Loops cannot be slow down, not in javaScript and not in other languages.
Also functions like sleep that a few languages have are not meant to make
loops slow, but to postpone the execution of blocks of codes - but that''s
server side, like a flush() method say.
ciao
Alberto Vallini
ciao
uhm why not using both? I mean an old way of doing soemthing doesn''t age:
the document.images collection is an useful tool: it grants you the option
to loop throughout ALL the available images with an array already arranged.
otherwise you''d have to arrange it yourself, either patching up a collection
by repeatedly calling in document.getElementById(''image101'') or by
document.getElementsByTagName("A")
the former is highly unpractical, the second is much slower than just using
an object which is already within the built in arrays of a loaded document.
It is not an issue of purist vs moderns: it is that I''m suggesting: use
both - dismissing the name just because they ADDED the id feature doesn''t
mean you have to give up the possibility to scan all your images with an
alrerady available collection. Again, name= is NOT deprecated.
Of course, feel free to dismiss my suggestion, but please: it is NOT a
suggestion of "old school" vs "new school": it is the suggestion that
everybody with javascript expereince would be likely to lend to you.
Of course, eventually do as you prefer. yet using two weapons instead than
one is better - we have not given up the rifle because we have the scuds.
ciao

Alberto
http://www.unitedscripters.com/

"TheKeith" <no@spam.com> ha scritto nel messaggio
news:X9********************@giganews.com...

TheKeith < no@spam.com>在消息中写道
新闻:6c ******************** @ giganews.com ...

"TheKeith" <no@spam.com> wrote in message
news:6c********************@giganews.com...
我正在写作一个带有while循环的脚本。我怎么能让它变得更慢
I''m writing a script with a while loop in it. How can I get it to go slower
这样它似乎不会一下子发生 - 所以它看起来很动画 - 基本上。我在
循环的最后一行尝试了setTimeout(500),但这只是搞砸了。任何帮助都会
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


赞赏 - 谢谢。

这就是我正在做的事情:

< 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< widthto){
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.



抱歉搞砸了消息,它包含了下半部分的副本

of发送给另一个用户的消息 - 只有前半部分是你的

问题 - 可以打开4个wiondows的错误!

ciao
sorry for the messed up message, it included a second half which was a copy
of a message sent to another user - only the first half was for your
question - mistakes that can ahppen with 4 wiondows open!
ciao


这篇关于放慢循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆