(function($){ $.fn.xfocus = function(options){ if(!$(this).size()){ return false; }; var $self = $(this); var $opt = $.extend({direction: 'h', order: 'asc', time: 2500, speed: 300, position: 'first', action: 'click', text: true}, options); var $i = 0; var $isstop = false; var $boxwidth = $self.width(); var $boxheight = $self.height(); var $box = $('.focus-box', $(this).wrapinner('
')).css({width: $boxwidth +'px', height: $boxheight +'px'}); var $pics = $('.focus-pics',$box); var $size = $('a', $box).size(); if($opt.order == 'desc')$i = ($size -1); switch($opt.direction){ case 'v': $pics.css({width: $boxwidth +'px', height: (($boxheight + 1) * $size) +'px'}); break; default: $pics.css({width: (($boxwidth + 1) * $size) +'px', height: $boxheight +'px'}); $('a', $pics).css({float: 'left'}); }; $('a, img', $pics).css({width: $boxwidth +'px', height: $boxheight +'px'}); var $html = '
'; if($opt.text){ $html+='
'; }; $html+='
'; $(this).append($html); $opt.lis = $('.l-btn li', this); switch($opt.action){ case 'hover': $opt.lis.hover(function(){ $i = $(this).index(); $isstop = true; $opt.actiontimer = settimeout(xswitch, 200); },function(){ $isstop = false; cleartimeout($opt.actiontimer); }); break; default: $opt.lis.click(function(){ $i = $(this).index(); xswitch(); }).hover(function(){ $isstop = true; },function(){ $isstop = false; }); }; function xswitch(){ $('.l-btn li', $self).removeclass().eq($i).addclass('selected'); xtext(); switch($opt.direction){ case 'v': $pics.animate({margintop: - $i * $boxheight +'px'}, $opt.speed); break; default: $pics.animate({marginleft: - $i * $boxwidth +'px'}, $opt.speed); }; }; function xtext(){ if(!$opt.text){ return false; }; var $data = $('.l-btn li', $self).eq($i).attr('xdata'); if($data == undefined){ $data = ''; }; if($data.indexof('$$') > -1){ $data = $data.split('$$'); $data = ''+ $data[0] +''+ $data[1]; }; $('.info', $self).html($data); }; if(isnan($opt.position)){ if($opt.position == 'first'){ xtext(); }else if($opt.position == 'last'){ $('.l-btn li', this).eq($size -1).click(); }else{ alert('error: [position:'+ $opt.position +']'); }; }else{ if($opt.position > ($size - 1))$opt.position = ($size-1); $('.l-btn li', this).eq($opt.position).click(); }; var $autoplay = setinterval(function(){ if($isstop)return false; if($i > ($size - 1)){$i = 0;}; if($i < 0){$i = ($size - 1);}; xswitch(); if($opt.order == 'asc'){ $i++; }else if($opt.order == 'desc'){ $i--; }else{ alert('error: [order:'+ $opt.position +']'); clearinterval($autoplay); }; }, $opt.time); return this; }; })(jquery);