开发者

How do I alternate display of 2 elements continuously in jQuery?

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜