views:

22

answers:

1

Hi

I have two image elements:

<img src="/image1.gif" id="id1" /><img src="/image2.gif" id="id2" />

I'm trying to create a continuous loop in jQuery whereby image1.gif is shown for 1 second, then disappears and image2.gif is shown for 1 second and so on, alternating for N seconds.

I've just about hit a wall with it.

Has anyone got any ideas?

Thanks in advance.

+1  A: 

To toggle, you can just use setInterval() and .toggle() both elements, effectively swapping them, like this:

$("#id2").hide(); //start with the frst
setInterval(function() {
  $("#id1, #id2").toggle();
}, 1000);
Nick Craver
Holy cow, that was easy. I was looking in completely the wrong direction and had ended up with reams of code. Cheers Nick
Andyh
@Andyh - welcome!
Nick Craver