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.
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);
精彩评论