jQuery.fn.imageScroller = function(params) { var p = params||{t:5000}; var thisUl=$(p.frame); var btnLeft=$(p.prev); var btnRight=$(p.next); var thisLi=$(p.child); var _auto = p.auto; var _itv; var w =thisLi.width(); var _t = p.t; var slideLeft = function() { btnLeft.unbind('click', slideLeft); thisUl.find('li:last').prependTo(thisUl); thisUl.css('marginLeft', -w); thisUl.animate({ 'marginLeft': 0 }, 350, function () { btnLeft.bind('click', slideLeft); }); return false; }; var slideRight = function() { btnRight.unbind('click', slideRight); thisUl.animate({ 'marginLeft': -w }, 350, function () { thisUl.css('marginLeft', '0'); thisUl.find('li:first').appendTo(thisUl); btnRight.bind('click', slideRight); }); return false; }; var init = function() { thisUl.width(thisLi.length * w); btnLeft.click(slideLeft).hover(slideStop, slideAuto); btnRight.click(slideRight).hover(slideStop, slideAuto); if (_auto) { slideAuto(); thisUl.hover(slideStop, slideAuto); } }; var slideAuto = function () { _itv = window.setInterval(slideRight, 5000); }; var slideStop = function () { window.clearInterval(_itv); }; init(); };