(function($) { $.fn.extend({ imgdemo:function(opt) { var opt = arguments[0] ? arguments[0] :false; var $button = $(this).children("li") ; //容器; var $sec = 3000 ; //自动播放默认时间; var $min = $button.last().width() ; //最小宽度; var $max = $button.first().width() ; //最大宽度; var $index = 1 ; //轮播开始索引号; $default = { //默认参数; speed : opt.speed ? opt.speed : "slow" , by : opt.by ? opt.by : "click" , auto : opt.auto ? opt.auto : false , sec : opt.sec ? opt.sec < 1000 ? 1000 : opt.sec : $sec , maxwidth: $max , minwidth: $min , index : $index }; $button.bind($default.by, this.run).autoplay(); //绑定事件; }, run:function() { //运行方法; var $obj = $(this); if ($obj.width() == $default.minwidth) { var timedo = window.settimeout(function() { $default.index = $obj.index(); $obj.anim(); }, 100); $obj.mouseout(function() { window.cleartimeout(timedo); }); } }, autoplay:function() { //自动播放; if ($default.auto) { var $this = $(this); $this.autodo(); $this.mouseover(function() { window.clearinterval(timel); }); $this.mouseout(function() { $this.autodo(); }); } }, autodo:function() { //播放方法; var $len = $(this).length - 1; var $this = $(this); timel = window.setinterval(function() { $this.eq($default.index).anim(); $default.index < $len ? $default.index++ :$default.index = 0; }, $default.sec); }, anim:function() { //动画方法; var $fx = function() { $(this).siblings("li").animate({ width : $default.minwidth, opacity : 1 }, $default.speed).css("cursor", "pointer"); $(this).animate({ width : $default.maxwidth, opacity : 1 }, $default.speed).css("cursor", "default"); $(this).siblings("li").children("div").fadeout(); $(this).children("div").fadeto($default.speed,0.8); $(this).dequeue(); }; $(this).queue($fx); } }); })(jquery);