setTimeout()javascript问题 [英] setTimeout( ) javascript question

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

问题描述

我正在使用setTimeout()连续调用一个随机调用的函数

在页面上旋转/显示2个图像。我需要帮助的部分是

第二张图像应该在第一张图像旋转3秒后旋转。我b $ b无法弄清楚如何完成3秒的延迟。我的代码是

粘贴在下面:


函数randPic(){

randPic1();

randPic2();


}


函数randPic1(){

picIndex = picIndex + 1;

if(picIndex> = middlepics.length)

picIndex = 0;

d.images [" pic1"]。src =" images / middle /" + middlepics [picIndex];

d.images [" pic1"]。alt = midalts [picIndex];


timerID = setTimeout(" randPic1()",3700);

}


函数randPic2(){

bottomPicIndex = bottomPicIndex + 1;

if(bottomPicIndex> = bottompics.length)

bottomPicIndex = 0;

d.images [" pic2"] .src =" images /

bottom /" + bottompics [bottomPicIndex];

d.images [" pic2"]。alt = bottomalts [bottomPicIndex];


timerID = setTimeout(" randPic2()",5500);

}


randPic ()函数是cal领导身体标签的onLoad事件。

您可能会有任何想法,我将不胜感激。

解决方案

于2007年2月13日在comp.lang.javascript中写道


我正在使用setTimeout()连续调用一个函数随机

在页面上旋转/显示2张图像。我需要帮助的部分是

第二张图像应该在第一张图像旋转3秒后旋转。我b $ b无法弄清楚如何完成3秒的延迟。我的代码是

粘贴在下面:


函数randPic(){

randPic1();

randPic2();

}



函数randPic(){

randPic1();

setTimeout(''randPic2()'',3000);

}


< body onload =" randPic(); ">


或:


< body onload =" setTimeout(''randPic2()'',3000); randPic1();" >


-

Evertjan。

荷兰。

(请更改x 我的电子邮件地址中的点数


2月13日,下午12:32,Evertjan。 < exjxw.hannivo ... @interxnl.net>

写道:


于2007年2月13日在comp.lang.javascript上写道


我正在使用setTimeout()连续调用一个随机调用的函数

旋转/显示2张图像在页面上。我需要帮助的部分是

第二张图像应该在第一张图像旋转3秒后旋转。我b $ b无法弄清楚如何完成3秒的延迟。我的代码是

粘贴在下面:


函数randPic(){

randPic1() ;

randPic2();


}



函数randPic(){

randPic1();

setTimeout(''randPic2()'',3000);

}


< body onload =" randPic();">


或:


< body onload =" setTimeout('''randPic2( ) '',3000); randPic1();" >


-

Evertjan。

荷兰。

(请更改x '我的电子邮件地址中的点数)



谢谢。我尝试了这两个选项并且他们工作了,除了

两个图像同时旋转的某个点(这是我们试图避免的b / b
)。你有没有办法防止这种情况发生?$ / b

-

Nikki


新手说:


>
2月13日下午12:32,Evertjan。 " < exjxw.hannivo ... @interxnl.net>
写道:


>写于2007年2月13日的comp.lang.javascript


我正在使用setTimeout()连续调用一个随机函数

在页面上旋转/显示2个图像。我需要帮助的部分是

第二张图像应该在第一张图像旋转3秒后旋转。我b $ b无法弄清楚如何完成3秒的延迟。我的代码是

粘贴在下面:


函数randPic(){

randPic1() ;

randPic2();


>}


函数randPic(){
randPic1();
setTimeout(''randPic2()'',3000);
}
< body onload =" randPic();">
或:

< body onload =" setTimeout(''randPic2()'',3000); randPic1();" >

- Evertjan。
荷兰。
(请将我的电子邮件地址中的x'更改为点数)



谢谢。我尝试了这两个选项并且它们有效但除了两个图像同时旋转的某些点(这是我们试图避免的)。你知道一种防止这种情况发生的方法吗?



让每个人安排另一个人改变,而不是安排

本身改变。

-


I am using setTimeout( ) to continuously call a function that randomly
rotates/displays 2 images on a page. The part I need help with is the
second image should rotate 3 seconds after the first image rotates. I
cannot figure out how to accomplish the 3 second delay. My code is
pasted below:

function randPic(){
randPic1();
randPic2();

}

function randPic1(){
picIndex = picIndex + 1;
if (picIndex>=middlepics.length)
picIndex = 0;
d.images["pic1"].src="images/middle/"+middlepics[picIndex];
d.images["pic1"].alt=middlealts[picIndex];

timerID=setTimeout("randPic1()",3700);
}

function randPic2(){
bottomPicIndex = bottomPicIndex + 1;
if (bottomPicIndex>=bottompics.length)
bottomPicIndex = 0;
d.images["pic2"].src="images/
bottom/"+bottompics[bottomPicIndex];
d.images["pic2"].alt=bottomalts[bottomPicIndex];

timerID=setTimeout("randPic2()",5500);
}

The randPic( ) function is called in the onLoad event of the body tag.
Any ideas you may have would be greatly appreciated.

解决方案

wrote on 13 feb 2007 in comp.lang.javascript:

I am using setTimeout( ) to continuously call a function that randomly
rotates/displays 2 images on a page. The part I need help with is the
second image should rotate 3 seconds after the first image rotates. I
cannot figure out how to accomplish the 3 second delay. My code is
pasted below:

function randPic(){
randPic1();
randPic2();

}

function randPic(){
randPic1();
setTimeout(''randPic2()'',3000);
}

<body onload="randPic();">

or:

<body onload="setTimeout(''randPic2()'',3000);randPic1();" >

--
Evertjan.
The Netherlands.
(Please change the x''es to dots in my emailaddress)


On Feb 13, 12:32 pm, "Evertjan." <exjxw.hannivo...@interxnl.net>
wrote:

wrote on 13 feb 2007 in comp.lang.javascript:

I am using setTimeout( ) to continuously call a function that randomly
rotates/displays 2 images on a page. The part I need help with is the
second image should rotate 3 seconds after the first image rotates. I
cannot figure out how to accomplish the 3 second delay. My code is
pasted below:

function randPic(){
randPic1();
randPic2();

}


function randPic(){
randPic1();
setTimeout(''randPic2()'',3000);
}

<body onload="randPic();">

or:

<body onload="setTimeout(''randPic2()'',3000);randPic1();" >

--
Evertjan.
The Netherlands.
(Please change the x''es to dots in my emailaddress)


Thanks. I tried both of these options and they worked except there is
some point at which both images rotate at the same time (which is what
we are trying to avoid). Do you know of a way to prevent this from
happening?

--
Nikki


Newbie said:

>
On Feb 13, 12:32 pm, "Evertjan." <exjxw.hannivo...@interxnl.net>
wrote:

> wrote on 13 feb 2007 in comp.lang.javascript:

I am using setTimeout( ) to continuously call a function that randomly
rotates/displays 2 images on a page. The part I need help with is the
second image should rotate 3 seconds after the first image rotates. I
cannot figure out how to accomplish the 3 second delay. My code is
pasted below:

function randPic(){
randPic1();
randPic2();

>}


function randPic(){
randPic1();
setTimeout(''randPic2()'',3000);
}

<body onload="randPic();">

or:

<body onload="setTimeout(''randPic2()'',3000);randPic1();" >

--
Evertjan.
The Netherlands.
(Please change the x''es to dots in my emailaddress)



Thanks. I tried both of these options and they worked except there is
some point at which both images rotate at the same time (which is what
we are trying to avoid). Do you know of a way to prevent this from
happening?

Have each one schedule the other to change, instead of scheduling
itself to change.
--


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

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