/** * @package Xslider - A slider plugin for jQuery * @version 0.5 * @author xhowhy **/ ;(function($){ $.fn.Xslider = function(options){var settings ={ affect: 'scrollx', //??? ??crollx|scrolly|fade|none speed: 1200, //?????? space: 6000, //?????? auto: true, //?????? trigger: 'mouseover', //?????? ????-ouseover?f?hover conbox: '.conbox', //??????id??lass ctag: 'a', //?????? ????? ttag: 'h3', //?????? ?????

switcher: '.switcher', //???????-d??lass stag: 'a', //???????? ????? current:'cur', //?????????????? controler:'.controler', //?????????????? rand:false //?????????????????? }; settings = $.extend({}, settings, options); var index = 1; var last_index = 0; var $conbox = $(this).find(settings.conbox),$contents = $conbox.find(settings.ctag); $conbox.width($(this).width()).height($(this).height()); var $ts = $conbox.find(settings.ttag); $ts.width($(this).width()); var $imgs = $conbox.find('img'); $imgs.width($(this).width()).height($(this).height()); var $controler = $(this).find(settings.controler),$prev = $controler.find('.prev'),$next = $controler.find('.next'); var $switcher = $(this).find(settings.switcher),$stag = $switcher.find(settings.stag); if(settings.rand) {index = Math.floor(Math.random()*$contents.length);$ts.eq(index).show();slide();}else{$ts.eq(0).show();} if(settings.affect == 'fade'){$.each($contents,function(k, v){(k === 0) ? $(this).css({'position':'absolute','z-index':9}):$(this).css({'position':'absolute','z-index':1,'opacity':0}); }); } function slide(){if (index >= $contents.length) index = 0; $stag.removeClass(settings.current).eq(index).addClass(settings.current); //var $ts = $contents.eq(index).find('h3'); switch(settings.affect){case 'scrollx': $conbox.width($contents.length*$contents.width()); $conbox.stop().animate({left:-$contents.width()*index},settings.speed); break; case 'scrolly': $contents.css({display:'block'}); $conbox.stop().animate({top:-$contents.height()*index+'px'},settings.speed); break; case 'fade': $contents.eq(last_index).stop().animate({'opacity': 0}, settings.speed/2).css('z-index',1) .end() .eq(index).css('z-index',9).stop().animate({'opacity': 1}, settings.speed/2) break; case 'none': $contents.hide().eq(index).show(); break; } $ts.hide(); $ts.eq(index).show().css({left:$contents.width()*index});//addClass(settings.current); last_index = index; index++; }; if(settings.auto) var Timer = setInterval(slide, settings.space); $stag.bind(settings.trigger,function(){_pause() index = $(this).index(); slide(); _continue() }); $prev.bind('click',function(){_pause() index = last_index - 1; if (index < 0) index = $contents.length - 1; slide(); _continue() }); $next.bind('click',function(){_pause() index = last_index + 1; slide(); _continue() }); $conbox.hover(_pause,_continue); function _pause(){ clearInterval(Timer); } function _continue(){ if(settings.auto)Timer = setInterval(slide, settings.space); } } })(jQuery);