Click to See Complete Forum and Search --> : Display images in a time delay


kjdix
04-21-2009, 07:55 AM
Hey,
I know this is probably very simple for everyone but im looking for some simple code that will display a series of six images, one after the other, for approx 5 seconds each. At present we have a static image with code

<img src=front.jpg align=right>


Any help would be much appreciated as ive been looking for code and have been unable to find anything simple.

Cheers.

coldwerturkey
04-21-2009, 12:50 PM
search javascript slideshow / image / delay / etc. What you're looking for needs to happen client-side not server-side.

shawty
04-28-2009, 06:52 PM
To support basic timing functions you simply need to use the javascript timer functions.

In your document load handler you would set an initial timer trigger to make the first call to your repeated function eg:


setTimeout("myFunction()",5000);


This is saying, set a timer to run for 5000 miliseconds (5 seconds), then when that time is up execute the command 'myFunction()'

What you would then do, is use what ever methods you need to manipulate and update your div/img/para etc usinc the document object, then befor exiting the function call 'setTimeout' again to call back into the function after another delay.

Anyone whos read any of my posts on here will know i'm a big fan of Jquery, and i would strongly suggest that you use that to manipulate your document objects, it really is childs play when you can change a picture by using somthing as simple as:


$('#myPicture').src="picture2.jpg";


Cheers

Shawty

JPnyc
04-29-2009, 05:07 PM
better to use setInterval(), it's already recursive. If you use timeout you have to call the function again at the end of itself. Also uses slightly more resource I think.

shawty
04-29-2009, 05:31 PM
yea, i think you may be right on the resource thing JP, i think iv'e read something to that effect somewhere else, as for it being recursive though i didn't realize it was.

I'm usually quite happy with setTimeout however, beacuse at some stage i generally want control of the stopping point of my timers, but then again i normally use timers to provide a chained series of events with a finite end.

Cheers

Shawty

Weedpacket
04-29-2009, 10:54 PM
I'd also recommend (still saying "setTimeout" because that's the example above)
setTimeout(myFunction,5000);instead of setTimeout("myFunction()",5000);The latter requires the argument string to be parsed every time before the runtime can get to the point where the former is already at.

shawty
04-29-2009, 11:15 PM
oop's...

My Bad.... :-)

It was supposed to be not enclosed in "", iv'e had my head buried to much in Perl scripts for the past few weeks.

Weedpacket
04-29-2009, 11:17 PM
Just you wait until you get to do that in PHP :evilgrin:

shawty
04-30-2009, 07:07 AM
Image display, or extra " marks... :-)

Same thing happens every time Iv'e been on a Perl bender, the language always clouds my judgment :-D

Be a while before I'm back at the PHP fully though, all my current projects are C# and windows mobile based.

Heh :cool:

Weedpacket
05-01-2009, 12:20 AM
Neither: functions as first-class entities. Something I actually miss about Perl.
function cartesian_product_iterator($a, $b)
{
$ca = count($a);
$cb = count($b);

$i = $j = -1;
return function()use($a, $b, $ca, $cb, &$i, &$j)
{
$i = ++$i % $ca;
if(!$i) ++$j;
return $j<$cb ? array($a[$i], $b[$j]) : null;
};
}

$first_iterator = cartesian_product_iterator(range(0, 5), range('a', 'e'));
$second_iterator = cartesian_product_iterator(range(17, 42), range('A', 'Z'));
while(null!==($first_pair = $first_iterator()))
{
echo '[', join(' ', $first_pair), '] ';
if(mt_rand(0,1))
{
if(null!==($second_pair = $second_iterator()))
{
echo '{', join(' ', $second_pair), '} ';
}
}
}

shawty
05-01-2009, 03:33 PM
Ahh... right, gotcha now... :-)