How can I blink with jQuery?

Nathaniel picture Nathaniel · Jul 29, 2010 · Viewed 7.8k times · Source

I would like to blink my menu text. I have this code, but it doesn't work with IE.

(function($)
{
    $.fn.blink = function(options) {
        var defaults = { delay:500 };
        var options = $.extend(defaults, options);

        return this.each(function() {
            var obj = $(this);
            setInterval(function() {
                if($(obj).css("color") == "rgb(255, 0, 0)")
                {
                    $(obj).css('color','#000000');
                }
                else
                {
                    $(obj).css('color','rgb(255, 0, 0)');
                }
            }, options.delay);
        });
    }
}(jQuery))

$(document).ready(function(){$('.blink').blink()})

Can someone help me? Thank you!

Answer

doug picture doug · Jul 29, 2010

The Mini-Effects plug-ins should be simpler here--very small and clearly efficient if this is all you need from the UI Effects Library (aside from those other essentials, "throb", "shake", and "bob").

Simple to use--just load the mini-effects plugin you need, then just call blink() on the element you want to blink.

<script type="text/javascript" charset="utf-8" src="javascripts/jquery.blink.min.js"></script>

Then, just call blink() on some large brightly-colored resource:

$(".selector").blink();