I am learning JQuery and trying to write my own Plug-in.
I have a 'Blinking' plug in. It just makes text blink.

Now I want to be able to stop the blinking (for what ever reason) at
the same time I want to keep the Plug-In styling.

So to make item blink I do

$('#myitem').blink();

Now to stop it I want to be able do something like this

$('#myitem').stopBlinking();

I am not sure how to go about it.... I've learned the 'event'
technique where I can bind to 'StopBlink' event and then do $
('#myitem').trigger('StopBlink');

But I would like to keep Plug-in type of call so I will be able to do
it like $('#myitem').stopBlinking();


-----Here is my blinking plug in----------------
(function($)
{
    $.fn.blink = function(options)
    {
        var opts = $.extend({}, $.fn.blink.defaults, options);
        var timer;
        return this.each(function()
        {
            var $this = $(this);
            var currentClass = opts.class1;
            timer = setInterval(function()
{DoTheBlink($this,opts,currentClass)}, 1000);
        });
    }

    function DoTheBlink($el,opts,currentClass)
    {

        var newClass = (currentClass == opts.class1) ? opts.class1 :
opts.class2;
        $el.toggleClass(newClass);
    };

    $.fn.blink.defaults = {
        class1: 'red',
        class2: 'blue'
    };

})(jQuery);


How do i add stopBlinking?

Thanks
George.

Reply via email to