...

View Full Version : multiple timeouts?



turpentyne
03-01-2012, 02:20 AM
I don't know how to work with timeouts. I have a simple blinking image. but I'm not sure how to set multiple timeouts?

Basically I want the image to blink to another one for 400, then return to the first image for 5000

here's the basic starting point I have:


<script type="text/javascript">

var img_off = new Image(); img_off.src = 'images/blink.png';
var img_on = new Image(); img_on.src = 'images/orho2.png';

function blink() {
var e = document.getElementById("blinking_orho");
e.src = (e.src == img_on.src) ? img_off.src : img_on.src;
setTimeout("blink();", 5000,);
}

</script>

felgall
03-01-2012, 02:29 AM
Replace


e.src = (e.src == img_on.src) ? img_off.src : img_on.src;
setTimeout("blink();", 5000,);

with


if (e.src == img_on.src) {
e.src = img_off.src;
setTimeout(blink, 400);
} else {
e.src = img_on.src;
setTimeout(blink,5000);
}

or switch the numbers the other way around if that's what you wanted (it isn't clear which image is to display for which interval).

Note that setTimeout expects a function as the first parameter, not a string.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum