开发者

Indicator Light with jQuery?

I have an image of a light off and a light on and would like it to switch back and forth between these images giving the impression a blinking light. Does anyone know of a Jquery function or plugin that can easily 开发者_运维知识库do this?

Thanks


You can do this with simple jQuery and CSS.

Define a class to represent the "on" state and toggle it using setInterval.

$(function() {
    setInterval(function() {
        $('.blinking-light').toggleClass('on');
    }, 1000);
}

The rest is just CSS.


If you want to fade between your images (which may be pretty, depending on the pictures), you could use jQuery's animation queue. Perhaps something like

    function blink()
    {
        $("#on").fadeIn(1000).delay(2000).fadeOut(1000, blink);
    }

Overlay the images so the the on image is on top of the off image.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜