(function(){ $.fn.Microslider = function(opt){ var def = { content:'#id-show-content', control:'#id-show-control', slider:'#id-show-slider', speed:350, pace:2000, width:340 }; def = $.extend({},def,opt); var num = $(def.content).find('li').length; var cur = 0; var timer = setInterval(function(){_animate();},def.pace); $(def.control).find('li').not(def.slider).each(function(i){ $(this).bind('mouseover',function(){ cur = i; var pos = $(this).position(); _pause(); $(def.slider).stop().animate({left:pos.left},def.speed,function(){ _continue(); }); $(def.content).stop().animate({left:-def.width*i},def.speed); }); }); function _pause(){clearInterval(timer);} function _animate(){ var next = (++cur)%num; var pos = $(def.control).find('li').eq(next).position(); $(def.slider).stop().animate({left:pos.left},def.speed); $(def.content).stop().animate({left:-def.width*next},def.speed); } function _continue(){timer = setInterval(function(){_animate();},def.pace);} } })(jQuery);