[jQuery] Re: My first plug in. Need comments.

2008-11-06 Thread George

Thanks,
I see your point..

George.

On Nov 6, 7:28 am, "Alexandre Plennevaux" <[EMAIL PROTECTED]>
wrote:
> Hi Georges !
>
> excellent way to learn.
>
> personally, i would use toggleClass()
> (http://docs.jquery.com/Attributes/toggleClass#class) and have the
> color set in the CSS file. As a rule, try always to use each
> technology for what it was meant:
>
> html > data
> css > styling
> javascript > behaviour
>
> so it would be:http://jsbin.com/osaxa
>
>
>
> On Thu, Nov 6, 2008 at 6:46 AM, George <[EMAIL PROTECTED]> wrote:
>
> > Guys, I am learning JQuery (and JavaScript) in general.
> > So I decided to write my first 'Blink' plug in.
> > It works but can you please take a look an tell me if something is
> > considered bad practice or can be done better.
>
> > (function($) {
> >    $.fn.blink = function(options) {
> >        var opts = $.extend({}, $.fn.blink.defaults, options);
> >        return this.each(function() {
> >            var $this = $(this);
> >            var currentColor = opts.color1;
>
> >            $this.css({backgroundColor: currentColor});
> >            window.setInterval(function (){DoTheBlink();},
> > 1000);
> >            function DoTheBlink()
> >            {
> >                if (currentColor == opts.color1)
> >                    currentColor = opts.color2;
> >                else
> >                    currentColor = opts.color1;
> >                $this.css({ backgroundColor: currentColor });
> >            }
> >        });
> >    };
>
> >    $.fn.blink.defaults = {
> >        color1: 'red',
> >        color2: 'blue'
> >    };
> > })(jQuery);
>
> > --USE-
> > hahaha
> > hahaha
> > hahaha
> > 

[jQuery] Re: My first plug in. Need comments.

2008-11-06 Thread Alexandre Plennevaux

Hi Georges !

excellent way to learn.

personally, i would use toggleClass()
(http://docs.jquery.com/Attributes/toggleClass#class) and have the
color set in the CSS file. As a rule, try always to use each
technology for what it was meant:

html > data
css > styling
javascript > behaviour

so it would be:
http://jsbin.com/osaxa



On Thu, Nov 6, 2008 at 6:46 AM, George <[EMAIL PROTECTED]> wrote:
>
> Guys, I am learning JQuery (and JavaScript) in general.
> So I decided to write my first 'Blink' plug in.
> It works but can you please take a look an tell me if something is
> considered bad practice or can be done better.
>
>
>
> (function($) {
>$.fn.blink = function(options) {
>var opts = $.extend({}, $.fn.blink.defaults, options);
>return this.each(function() {
>var $this = $(this);
>var currentColor = opts.color1;
>
>$this.css({backgroundColor: currentColor});
>window.setInterval(function (){DoTheBlink();},
> 1000);
>function DoTheBlink()
>{
>if (currentColor == opts.color1)
>currentColor = opts.color2;
>else
>currentColor = opts.color1;
>$this.css({ backgroundColor: currentColor });
>}
>});
>};
>
>
>$.fn.blink.defaults = {
>color1: 'red',
>color2: 'blue'
>};
> })(jQuery);
>
>
> --USE-
> hahaha
> hahaha
> hahaha
>