问题描述
我在每个列表项移动之前创建延迟时遇到问题
(
)。选择任意数量的列,垂直布局和视图作为网页
页面。他们将在整个列表项之前稍微延迟
从左到右转换为从上到下的顺序。在每个项目移动之前我预计会延迟
。看起来我必须将缓冲区刷新到
让setTimeout工作,但我不认为Javascript中有一个内置的刷新
函数了。或者setTimeout只会延迟它第一次调用时调用的
函数,并随后无延迟地调用
函数。在这个脚本中,我有:
setTimeout(" funtest(" + li_count +"," + pos_change_left +"," +
pos_change_top +")",700);
调用:
函数funtest(aaa,bbb,ccc)
{
var li = $(''mylist'')。getElementsByTagName(''LI'');
li [aaa] .style .position =''relative'';
li [aaa] .style.left = bbb +''px'';
li [aaa] .style.top = ccc +''px'';
}
一次为每个移动的李(其中20个),但是有只有一次延迟,
然后他们都被感动了。如果我在函数中发出警报,那么它就会触发20次,一次是在每次改变位置之前,所以
为什么不存在20次延迟(每次移动前一次)而不只是一次?
I''m having a problem creating a delay before each list item gets moved
( http://www.polisource.com/PublicMisc...meout-bug.html
). Choose any number of columns, vertical layout, and view as a web
page. They''ll be a small delay before the entire bunch of list items
converts from left-to-right to top-to-bottom order. I expected a delay
before each item is moved. It looks like I have to flush the buffer to
get setTimeout to work, but I don''t think there''s a built-in flush
function in Javascript anymore. Or else setTimeout only delays the
function it calls the first time it''s called and subsequently calls the
function with no delay. In this script I have:
setTimeout("funtest(" + li_count + "," + pos_change_left + "," +
pos_change_top + ")",700);
which calls:
function funtest(aaa,bbb,ccc)
{
var li = $(''mylist'').getElementsByTagName(''LI'');
li[aaa].style.position = ''relative'';
li[aaa].style.left = bbb + ''px'';
li[aaa].style.top = ccc + ''px'';
}
once for each li that''s moved (20 of them), but there''s only one delay,
then they''re all moved. If I put an alert in the function, it''s
triggered 20 times, once before every change in position of a li, so
why aren''t there 20 delays (one before each move) instead of just one?
推荐答案
不是我的专业领域,但我想我之前听过有人在说
当JS函数返回时执行所有样式表更新。
与javascript的1个线程有关,但我不确定。
它与刷新缓冲区无关。哪个缓冲区?
如果你想让它们一个接一个地移动,在excuting函数中给出下一个setTimeOut
(在这种情况下最有趣) 。
或者确保所有setTimeout调用的间隔都在增加。
像这样:
setTimeout(" funtest(''bla'' ,''bla'',''bluh'')",700);
setTimeout(" funtest(''bla'',''bla2'',''bluh''' )",1400);
等
我无法通过您的代码看到setTimeOut的实现位置和方式
现在。
问候,
Erwin Moller
Hi,
Not my area of expertise, but I think I heard somebody in here say before
that all stylesheet-updates are executed when the JS-function returns.
Has something to do with 1 thread for javascript, but I am not sure.
It has nothing to do with ''flushing a buffer''. Which buffer?
And if you want them to move one after each other, give the next setTimeOut
from within the excuting function (funtest in this case).
Or make sure all setTimeout calls have an increasing interval.
Like this:
setTimeout("funtest(''bla'',''bla'',''bluh'')",700);
setTimeout("funtest(''bla'',''bla2'',''bluh'')",1400);
etc.
I cannot see by your code where and how the setTimeOut is implemented right
now.
Regards,
Erwin Moller
这篇关于setTimeout仅在循环中第一次延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!