473,761 Members | 2,384 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

setTimeout() & setInterval() for DOM slideshow

I have a stack of DOM elements and I have stored their IDs in an array. I
want to press a button - this code is from that button's event's function-
and have a slideshow as each element is brought to the top, in turn. All
this, with a user definable delay (currently fixed in the code at 5 secs). I
cannot get the loop to stop while the interval timer is counting the time.

Help please :o?

Greg

===code below====

var delayed = 5000;
var numberOfSteps = picDescPairArra y.length; //this array contains element
IDs for items in a z-order stack
//if there is more than one item in the array, make the z-index 3 for all
of them
if (numberOfSteps > 1){
//change the z-index of all the items to 3
for (i=0; i <= (picDescPairArr ay.length-1); i++){
document.getEle mentById(picDes cPairArray[i]).style.zIndex = 3;
}

//change the z-index of each item to 5 in turn,
//(changing the previous item's z-index back to 3, providing it isn't the
first one)
for (j=0; j <= (picDescPairArr ay.length-1); j++){
if (j >= 1){document.get ElementById(pic DescPairArray[j-1]).style.zIndex =
3;}//the previous item goes down the stack

//a test line without the timer code - seems to work?
//document.getEle mentById(picDes cPairArray[j]).style.zIndex = 5;
alert('next?');

//the next item comes up to the top after a delay of 5 secs - well, it
should???
a=setInterval(" document.getEle mentById(picDes cPairArray[j]).style.zIndex
= 5;",delayed);
// I tried - setTimeout('exp r',delayed) ...without the clearInterval(a ),
obviously ;o)
}
}
clearInterval(a );
Jul 20 '05 #1
1 2828
On Mon, 23 Feb 2004 01:21:35 -0000, Noh Way <No*****@Jose.c om> wrote:
I have a stack of DOM elements and I have stored their IDs in an
array. I want to press a button - this code is from that button's
event's function - and have a slideshow as each element is brought
to the top, in turn. All this, with a user definable delay
(currently fixed in the code at 5 secs). I cannot get the loop to
stop while the interval timer is counting the time.


Your code requires some restructuring, which I've attempted below.
Unfortunately, without the containing page, I can't test it so I'll have
to leave it to you.

If there are any further problems, please post a URL, or a sample of the
HTML, for this. I, and others, can then check any solutions before posting
them.

var delayed = 5000;
var numberOfSteps = picDescPairArra y.length;
var timerID = null;

if ( numberOfSteps > 1 ) {
var j = 0;

setZIndex( getObjRef( picDescPairArra y[ 0 ]), 5 );
for ( var i = 1; i < numberOfSteps; ++i ) {
setZIndex( getObjRef( picDescPairArra y[ i ]), 3 );
}

timerID = setInterval( function() {
setZIndex( getObjRef( picDescPairArra y[ j++ ]), 3 );
setZIndex( getObjRef( picDescPairArra y[ j ]), 5 );
if( j == numberOfSteps - 1 ) clearInterval( timerID );
}, delayed );
}

function getObjRef( id ) {
if ( document.getEle mentById ) {
return document.getEle mentById( id );
} else if ( document.all ) {
return document.all[ id ];
}
return null;
}

function setZIndex( obj, index ) {
if( obj && obj.style && 'undefined' != typeof obj.style.zInde x )
obj.style.zInde x = index;
}

Hope that helps,
Mike

--
Michael Winter
M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2687
by: Robert Mark Bram | last post by:
Howdy All! I would like to find since when did different versions of browsers and/or JavaScript/JScript/ECMAScript support the SetTimeout and SetInterval methods.. this is for compatibility reasons. Thanks for any advice! Rob :)
1
16109
by: Weston C | last post by:
In the course of trying to build a simple clock, I've run into a problem using the setInterval (and setTimeout) function. http://weston.canncentral.org/misc/tkeep/tkeep.html http://weston.canncentral.org/misc/tkeep/tkeep.jss function fieldToClock(fieldId) { var field = document.getElementById(fieldId); alert("Starting a clock in text field " + fieldId + "(" + field
1
8905
by: John | last post by:
Michael Winter <M.Winter@blueyonder.co.invalid> wrote in message news:<opr3wd8yvj5vklcq@news-text.blueyonder.co.uk>... > On 24 Feb 2004 14:13:47 -0800, John <johnmark@fastermail.com> wrote: > > > I would like to use setTimeout and window.open methods to pop up > > window every 5 minutes. I can only manage to make the window to pop up > > only twice. > > > > function openWindow() { > > window.open("popupwindow.htm",...
5
2579
by: oliver | last post by:
Hi, the structure of my source code is like this: <script> C = function(){ //some initialization } C.prototype.start = function{ //some action
18
2203
by: Frances Del Rio | last post by:
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...
4
5234
by: E | last post by:
I am having trouble with setTimeout working on a second call to the setTimeout function from a second page which is an html page. Here is the scenario. I have a web page and onload it calls a javascript function which calls setTimeout and will process a second javascript function "Warn" just before the session expires. The Warn function displays an html page with a button. A second timer is started to cause the html page to close...
1
1720
by: Joris Lambrecht | last post by:
Hi people, Please take a look at the issue i talk about below. (yes i do realise such functions are publicaly available) The page i'm using uses JSON defined array of image files with information for the title property of the img tag. The functions i wrote below are sort of working since it needs an alert() to work the slides ???
15
3796
by: nikki_herring | last post by:
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();
2
5441
by: tequilamala | last post by:
I wanna put some images on my page that change everyfew seconds or so. The problem is that when the "slideshow" begins the veryfirst image is a blank and then it goes into the show. How do I get rid of the first blank? Heres the code: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>HomeArray</title>
0
9336
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10111
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8770
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7327
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6603
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5364
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3866
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3446
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.