// javascript document (function ($) { $.fn.scroll = function (options) { //榛樿閰嶇疆 var defaults = { speed: 30, //婊氬姩閫熷害涓�0-100涔嬮棿 direction: 'vertical' //鏂瑰悜锛歷ertical鍚戜笂婊氬姩,horizantal鍚戝乏婊氬姩 }; var opts = $.extend({}, defaults, options), intid = []; function marquee(obj, step, direction) { if (direction == 'horizantal') { obj.find("ul").animate({ marginleft: '-=1' }, 0, function () { var s = math.abs(parseint($(this).css("margin-left"))); if (s >= step) { $(this).find("li").slice(0, 1).appendto($(this)); $(this).css("margin-left", 0); } }); } else if (direction == 'vertical') { obj.find("ul").animate({ margintop: '-=1' }, 0, function () { var s = math.abs(parseint($(this).css("margin-top"))); if (s >= step) { $(this).find("li").slice(0, 1).appendto($(this)); $(this).css("margin-top", 0); } }); } } this.each(function (i) { var speed = 0 < 100 - opts["speed"] && 100 - opts["speed"] <= 100 ? 100 - opts["speed"] : 30; var direction = opts["direction"] == 'vertical' || opts["direction"] == 'horizantal' ? opts["direction"] : 'vertical'; var _this = $(this); intid[i] = setinterval(function () { var sh; if (direction == 'horizantal') { sh = _this.find("ul").find("li:first").outerwidth(true); } else { sh = _this.find("ul").find("li:first").outerheight(true); } marquee(_this, sh, direction); }, speed); _this.hover(function () { clearinterval(intid[i]); }, function () { intid[i] = setinterval(function () { var sh; if (direction == 'horizantal') { sh = _this.find("ul").find("li:first").outerwidth(true); } else { sh = _this.find("ul").find("li:first").outerheight(true); } marquee(_this, sh, direction); }, speed); }); }); } })(jquery);