的setTimeout [英] setTimeOut

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

问题描述



这段代码应该以一秒钟的间隔翻转imgs,但它会更快地翻转它们,它似乎在第一次翻转它们/>
秒,翻转它们的速度越快,而不是其他的b / b方式...(我的意思是在我看来,我放在那里的秒数越多

更多秒应该通过betw。翻转...每张照片都在一个div中,每个

div的z-index为0,1,2等。 )

http://www.francesdelrio.com/cassini

(请重新加载几次,我的东西加载有点慢b / c我的网站托管

国外,他们的int''l流量较慢.. )


代码:


var photos = new

数组(一,二) ,三个,四个,五个,六个,sev en,八个)

函数flip(){

for(i = 1; i&l t; photos.length; i ++){

var photoDiv = eval(''document.getElementById(''+" photos [i]" +'')'')

var doIt = photoDiv.style.visibility =" visible"

setTimeout(" doIt",1000)

}

}


谢谢.. Frances


this code is supposed to flip imgs at intervals of one second, but it
flipps them much faster, it seems it flips them all in that first
second, the more seconds the faster it flips them, instead of the other
way around... (I mean it seems to me the more seconds I put in there the
more seconds should go by betw. flips... each photo is in a div, each
div has a z-index of 0, 1, 2, etc..)

http://www.francesdelrio.com/cassini
(pls reload a few times, my stuff loads a bit slow b/c my site is hosted
abroad, their int''l traffic is slower..)

code:

var photos = new
Array("one","two","three","four","five","six","sev en","eight")
function flip() {
for (i=1; i < photos.length; i++) {
var photoDiv = eval(''document.getElementById('' + "photos[i]" + '')'')
var doIt = photoDiv.style.visibility = "visible"
setTimeout("doIt",1000)
}
}

thank you.. Frances

推荐答案

2004年9月23日星期四23:58:43 - 0400,Frances Del Rio写道:
On Thu, 23 Sep 2004 23:58:43 -0400, Frances Del Rio wrote:
for(i = 1; i< photos.length; i ++){
.... setTimeout(" doIt", 1000)
for (i=1; i < photos.length; i++) { .... setTimeout("doIt",1000)




...试试

setTimeout(..,i * 1000);


HTH


-

Andrew Thompson
http://www.PhySci.org/codes/ Web& IT帮助
http://www.PhySci.org/ 开源软件套件
http://www.1point1C.org/ Science&技术
http://www.lensescapes.com/ 图像逃脱世俗



...try
setTimeout(.., i*1000);

HTH

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.lensescapes.com/ Images that escape the mundane




" Frances Del Rio" < FD *** @ yahoo.com>在留言中写道

新闻:2r ************* @ uni-berlin.de ...

"Frances Del Rio" <fd***@yahoo.com> wrote in message
news:2r*************@uni-berlin.de...

此代码应该以一秒的间隔翻转imgs,但是它会更快地翻转它们,似乎它会在第一次翻转它们时,它翻转它们的速度越快,而不是另一个
周围的方式...(我的意思是在我看来,我放在那里的秒数越多,
应该更多的秒数。翻转...每张照片都在一个div中,每个
div的z-index为0,1,2等。)

http://www.francesdelrio.com/cassini
(请重新加载几次,我的东西加载有点慢b / c我的网站在国外托管
int''l流量较慢..)

代码:

var photos = new
数组(one,two,三个,四个,五个,六个,sev en,八个功能n flip(){
for(i = 1;我< photos.length; i ++){
不会引用第一个数组元素var photoDiv = eval(''document.getElementById(''+" photos [i]" +'')'')
eval是不必要的并且通常不应该用于返回对象

引用

var photoDiv = document.getElementById(photos [i]); var doIt = photoDiv.style.visibility =" visible"
doIt always =" visible" setTimeout(" doIt",1000)
第一个参数需要函数引用或有效表达式。更进一步

超时不会像我想的那样工作,因为当你调用setTimeout时循环没有
stoop 1秒钟。它只是在循环中不断下降,所有图像都会立刻显示出来。如果J博士正在倾听他的话,那么
是这类事情的专家,但你最好解释一下你在做什么。例如每隔一段时间打开/关闭图像;在一个系列中转换卡片每隔一段时间
。 }
}
取决于你在做什么,数组和ID的使用是不必要的
。您可以将它们包装在id =" wrapper"的div中并循环使用

他们使用wrapper.children(i)来引用每个对象。我假设您使用

代码将每个图像放在一个单独的div中。根据你想要达到的目标,这并不总是一个好的想法。如果它定位

你可以使用图片标签获得相同或更好的结果或

< p>< img ...或< span> ;< img

希望这会有所帮助。 Jimbo
谢谢.. Frances

this code is supposed to flip imgs at intervals of one second, but it
flipps them much faster, it seems it flips them all in that first
second, the more seconds the faster it flips them, instead of the other
way around... (I mean it seems to me the more seconds I put in there the
more seconds should go by betw. flips... each photo is in a div, each
div has a z-index of 0, 1, 2, etc..)

http://www.francesdelrio.com/cassini
(pls reload a few times, my stuff loads a bit slow b/c my site is hosted
abroad, their int''l traffic is slower..)

code:

var photos = new
Array("one","two","three","four","five","six","sev en","eight")
function flip() {
for (i=1; i < photos.length; i++) { will not reference the first array element var photoDiv = eval(''document.getElementById('' + "photos[i]" + '')'') eval is unnecessary and in general shouldn''t be used to return object
references as such
var photoDiv = document.getElementById(photos[i]); var doIt = photoDiv.style.visibility = "visible" doIt always = "visible" setTimeout("doIt",1000) first parameter wants a function reference or a valid expression. Further
the timeout won''t work the way I think you intend since the loop doesn''t
stoop for 1 second when you call setTimeout. It just keeps falling through
the loop and all your images will be shown at once. If Dr J is listening he
is an expert on this type of thing but you better explain what you''re trying
to do. e.g. turn images on/off at intervals; turn cards in a series at one
second intervals. }
} depending on what you''re doing, the use of the array and the Ids is
unnecessary. You could wrap them in a div with id="wrapper" and loop through
them using wrapper.children(i) to reference each object. I assume from your
code that you have each image in a separate div. This is not always a good
idea again depending on what you''re trying to achieve. If it''s positioning
you can achieve the same or better results just using the image tags or
<p><img ... or <span><img
Hope this helps. Jimbo
thank you.. Frances





JJ Cale写道:


J. J. Cale wrote:
Frances Del Rio < FD *** @ yahoo.com>在消息中写道
新闻:2r ************* @ uni-berlin.de ...
"Frances Del Rio" <fd***@yahoo.com> wrote in message
news:2r*************@uni-berlin.de...
此代码应该翻转每隔一秒钟就会发出一次,但是它会更快地翻转它们,似乎它会在第一次翻转它们时,它翻转它们的速度越快,而不是其他的越多
周围的方式...(我的意思是在我看来,我放在那里的秒数越多,
应该更多的秒数。翻转...每张照片都在div中,每个照片都有一个z-index为0,1,2等。)

http://www.francesdelrio.com/cassini
(请重新加载几次,我的东西加载有点慢b / c我的网站在国外托管,他们的int''l交通较慢..)

代码:

var photos = new
数组(一,二,三, ;四个,五个,六个,偶数,八个)
功能翻转(){
for(i = 1;我< photos.length; i ++){
this code is supposed to flip imgs at intervals of one second, but it
flipps them much faster, it seems it flips them all in that first
second, the more seconds the faster it flips them, instead of the other
way around... (I mean it seems to me the more seconds I put in there the
more seconds should go by betw. flips... each photo is in a div, each
div has a z-index of 0, 1, 2, etc..)

http://www.francesdelrio.com/cassini
(pls reload a few times, my stuff loads a bit slow b/c my site is hosted
abroad, their int''l traffic is slower..)

code:

var photos = new
Array("one","two","three","four","five","six","s even","eight")
function flip() {
for (i=1; i < photos.length; i++) {



不会引用第一个数组元素



will not reference the first array element

var photoDiv = eval(''document.getElementById(''+"照片[i]" +'')'')
var photoDiv = eval(''document.getElementById('' + "photos[i]" + '')'')



eval是不必要的,一般不应该用来返回对象
引用
var photoDiv = document.getElementById(photos [i]);



eval is unnecessary and in general shouldn''t be used to return object
references as such
var photoDiv = document.getElementById(photos[i]);

var doIt = photoDiv.style.visibility =" visible"
var doIt = photoDiv.style.visibility = "visible"


doIt always =" visible"



doIt always = "visible"

setTimeout(" doIt",1000)
setTimeout("doIt",1000)



第一个参数需要函数引用或有效表达。更进一步
超时不会像我想的那样工作,因为当你调用setTimeout时,循环不会弯腰1秒钟。它只是在循环中不断下降,所有图像都会立刻显示出来。如果J博士在听,他是这类事情的专家,但你最好解释一下你在做什么。例如每隔一段时间打开/关闭图像;每隔一段时间翻一次系列卡。



first parameter wants a function reference or a valid expression. Further
the timeout won''t work the way I think you intend since the loop doesn''t
stoop for 1 second when you call setTimeout. It just keeps falling through
the loop and all your images will be shown at once. If Dr J is listening he
is an expert on this type of thing but you better explain what you''re trying
to do. e.g. turn images on/off at intervals; turn cards in a series at one
second intervals.

}
}



取决于你的''重做,



depending on what you''re doing,




非常感谢你的帮助..这只是一个学习练习......

(需要学习如何从头开始实现我自己的循环..)我只是简单地想要img每隔2秒左右翻转一次,那就是它......就是......我是
实施了你的代码(但不明白''总是='可见'''',

不确定那条线,把它排除在外..)现在循环一次通过

然后停止....我希望它在完成时重新开始,就像幻灯片

显示到达终点然后重新开始...我知道我需要一旦完成就再次调用

函数,但不确定如何再次调用函数

右外循环(内部函数)但仍然只通过循环

一次..(然后得到一个 ;内存不足错误,从未见过这个..)


现在尝试使用相同的w / rollovers而不是hide / show divs ...


var photos = new

Array(one,two,three,four,five,six," sev en"," 8")

function flip(){

for(i = 1;我< photos.length; i ++){

var doIt =" cassini.src =''images /" + photos [i] +" .jpg''"

// one.jpg,two.jpg,three.jpg等..

setTimeout(" ; doIt",i * 1000)

}

}


这里我没有......(我看到了闪烁..就像imgs翻转真的很快或

东西..)我非常理解循环的概念,我有一个

与usu的艰难时期。在循环中组织stmts ...再次,谢谢

你非常感谢你的帮助.. Frances



thank you very much for yr help.. this is simply a learning exercise...
(need to learn how to implement my own loops from scratch..) I simply
want imgs to flip every 2 seconds or so for ever, that''s it.... I
implemented yr code (but don''t understand ''doIt always = "visible"'',
wasn''t sure about that line, left it out..) now cycle goes thru once
then stops.... I want it to start over when it finishes, like a slide
show that reaches the end then starts again... I know I need to call
function again once it''s done, but not sure how.. called function again
right outside loop (inside function) but still went thru loop only
once.. (and then get an "out of memory" error, had never seen this..)

now am trying same w/rollovers instead of hide/show divs...

var photos = new
Array("one","two","three","four","five","six","sev en","eight")
function flip() {
for (i=1; i < photos.length; i++) {
var doIt = "cassini.src = ''images/" + photos[i] + ".jpg''"
// one.jpg, two.jpg, three.jpg, etc..
setTimeout("doIt",i*1000)
}
}

here I get NOTHING.... (I see a flicker.. like imgs flip really fast or
something..) I understand very well the concept of loops, what I have a
hard time with usu. is organizing stmts inside the loop... again, thank
you very much for yr help.. Frances


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

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