(function($){ $.fn.extend({ reelText: function(options) { //declaramos variables predeterminadas var defaults = { prevBtn: "#prevBtn", nextBtn: "#nextBtn", wrapTxt: "#wrapReel", activo: 0 } var options = $.extend(defaults,options); //Iterate over the current set of matched elements return this.each(function() { var o = options; var obj = $(this); //ocultamos listado obj.css("display","none"); var cantItems = $("li" , obj).length; txtList = new Array(); for(var i=0; i < cantItems ; i++){ var itemLi = $("li" , obj)[i]; var txt = $(itemLi).html(); txtList.push(txt); } cambiaReel(); $(o.prevBtn).mousedown(function(){ if(o.activo == 0) { o.activo = cantItems -1;} o.activo --; cambiaReel(); return false; }); $(o.nextBtn).mousedown(function(){ if(o.activo == cantItems -1){ o.activo = -1;} o.activo ++; cambiaReel(); return false; }); }); function cambiaReel(){ var elem = options.wrapTxt; $(elem).fadeOut(200,function(){ $(elem).html(txtList[options.activo]); $(elem).fadeIn(); }); } } }); })(jQuery);