My rotator plugin, need your opinion
Hi everyone,
i'm a new Jquery User and i need your opinion about my plugin, let me show you the code :
First, html code :
- <div class="rotator">
- <ul>
- <li><p>First item</p></li>
- <li><p>Second item</p></li>
- <li><p>Third item</p></li>
- </ul>
- </div>
Now, the rotator plugin :
- (function($) {
- $.fn.rotator = function(params) {
- params = $.extend( { speed: 5000 }, params);
- var t = this;
- var nbItems = $("ul li", this).size();
- $("ul li:first", this).nextAll("li").fadeOut(0, 0);
- var i = (i > 0) ? i : 0;
-
- rotator();
- function rotator()
- {
- $("ul li:eq("+i+")", t).fadeIn("slow");
- $("ul li:eq("+i+")", t).delay(params.speed).fadeOut("slow", function()
- {
- $(this).hide(rotator);
- });
- if(i == (nbItems-1)) { i = 0; }
- else { i++; }
- }
- return this;
- };
- })(jQuery);
And now, i launch my plugin like that :
- $(document).ready(function() {
- $(".rotator").rotator({ speed: 5000 });
- });
That's work fine but i want to know if this plugin can be optimized ?
Thank you so much for your help ;)