// JavaScript Document /* * $('.myBanner').myBanner({ * direction:'fade', // 动画类型 * buttonList:'.page', // 按钮列表 * attrCurrent:'#current', // 触发按钮时添加的属性 * number:false, // true / false (有数字 / 无数字) * speed:1000, // 切换速度 * time:4000, // 切换间隔 * eventA:'mousedown', // 鼠标事件 * eventB:'mouseup' * }); */ (function($){ $.fn.myBanner=function(options){ $.fn.myBanner.defaults={ direction:'left', // 动画类型 top, left, fade buttonList:'.page', // 按钮列表 attrCurrent:'#current', // 触发按钮时添加的属性 number:false, // true / false (有数字 / 无数字) speed:200, // 切换速度 time:3000, // 切换间隔 eventA:'mouseover', // 鼠标事件 eventB:'mouseout' }; var opts=$.extend({}, $.fn.myBanner.defaults, options); return this.each(function(){ var $this=$(this); var $element=$this.children(); var $child=$element.children("li"); var $id; var $attr; var index=0; var p = $(".bann_wen p") if((opts.buttonList).substr(0, 1)=='.'){ $id='class'; }else{ $id='id'; }; $this.append('
'); for(var num=1; num<=$child.length; num++){ if(opts.number==false){ $(opts.buttonList).append(''); }else{ $(opts.buttonList).append(''+ num +''); }; }; if((opts.attrCurrent).substr(0, 1)=='.'){ $attr='class'; }else{ $attr='id'; }; $(opts.buttonList).children().eq(0).attr($attr, (opts.attrCurrent).substr(1)); function animateFun(){ index++; if(index>=$child.length){ index=0; }; $(opts.buttonList).children().eq(index).attr($attr, (opts.attrCurrent).substr(1)).siblings().removeAttr($attr, (opts.attrCurrent).substr(1)); //$child.eq(index).show().siblings().hide(); var $scroll; if(opts.direction=='top'||opts.direction=='bottom'){ $scroll=$child.outerHeight(); $element.stop().animate({ height:'1000000%', top: -($scroll * index)}, opts.speed); }else if(opts.direction=='left'||opts.direction=='right'){ $child.css('float','left'); p.css('float','left'); $scroll=$child.outerWidth(); $element.stop().animate({ width:'1000000%', left: -($scroll * index)}, opts.speed); }else if(opts.direction=='fade'){ $child.hide(); p.hide(); $child.eq(index).fadeIn(opts.speed).siblings().hide(); p.eq(index).fadeIn(opts.speed).siblings().hide(); }else{ $child.eq(index).show().siblings().hide(); p.eq(index).show().siblings().hide(); }; }; var timeout=setInterval(animateFun, opts.time); $(opts.buttonList).children().bind(opts.eventA, function(){ clearInterval(timeout); index=$(this).index()-1; animateFun(); //$(this).attr($attr, (opts.attrCurrent).substr(1)).siblings().removeAttr($attr, (opts.attrCurrent).substr(1)); }).bind(opts.eventB, function(){ timeout=setInterval(animateFun, opts.time); }); }); }; })(jQuery);