(function ($) { var timers = []; function nextmove(obj, step) { obj.find("ul").animate({ marginleft: -step }, 300, 'swing', function () { $(this).find("li").slice(0, 1).appendto($(this)); $(this).css("margin-left", 0); }); } function premove(obj, step) { var ul = obj.find("ul"); ul.css('margin-left', -step); ul.find("li").last().prependto(ul); ul.animate({ marginleft: 0 }, 300, 'swing', function () { ul.css("margin-left", 0); }); } function downmove(obj, step) { obj.find("ul").animate({ margintop: -step }, 300, 'swing', function () { $(this).find("li").slice(0, 1).appendto($(this)); $(this).css("margin-top", 0); }); } function upmove(obj, step) { var ul = obj.find("ul"); ul.find("li").last().prependto(ul); ul.css('margin-top', -step); ul.animate({ margintop: 0 }, 300, 'swing', function () { ul.css("margin-top", 0); }); } var methods = { init: function (options) { var defaults = { speed: 0, direction: 'horizantal' }; var opts = $.extend({}, defaults, options); return this.each(function (i) { var speed = opts["speed"] < 1000 ? 3000 : opts["speed"]; var direction = opts["direction"] == 'vertical' || opts["direction"] == 'horizantal' ? opts["direction"] : 'vertical'; var _this = $(this); var ul = _this.find("ul"), pre = $(".pre20"),/*_this.find(".pre20")*/ next = $(".next20");/*_this.find(".next20")*/ var sh, ismove, ishori, move, lmove, rmove; if (direction == 'horizantal') { ismove = _this.width() < ul.width(); ishori = true; move = nextmove; lmove = premove; rmove = nextmove; sh = ul.find("li:first").outerwidth(true); } else { ismove = _this.height() < ul.height(); ishori = false; move = downmove; lmove = upmove; rmove = downmove; sh = ul.find("li:first").outerheight(true); } if (ismove) { timers[i] = setinterval(function () { move(_this, sh); }, speed); _this.hover(function () { clearinterval(timers[i]); }, function () { timers[i] = setinterval(function () { move(_this, sh); }, speed); clearinterval(timers[i]); }); pre.click(function () { lmove(_this, sh); clearinterval(timers[i]); }); next.click(function () { rmove(_this, sh); clearinterval(timers[i]); }); clearinterval(timers[i]); } /* setinterval(function(){rmove(_this, sh); $(".single ul li").removeclass("active"); $(".single ul li:eq(2)").addclass("active");},5000);*/ }); }, destroy: function () { return this.each(function (i) { _this = $(this); clearinterval(timers[i]); _this.find('ul').css({ 'margin-top': 0 }); _this.find('ul').css({ 'margin-left': 0 }); _this.unbind("mouseenter").unbind("mouseleave"); _this.find('.pre').unbind('click'); _this.find('.next').unbind('click'); }); } } $.fn.mysinglescroll = function (options) { var method = arguments[0]; if (methods[method]) { method = methods[method]; } else if (typeof method == 'object' || !method) { method = methods.init; } else { $.error('error'); return this; } return method.apply(this, arguments); } })(jquery)