(function($) { $.fn.extend({ 'loopmovement' : function(config) { var _this = this, _timer = null, _defaultconfig = $.extend({}, {"direction":"top", "speed":"80"}, config); _this.addclass(_defaultconfig.direction); //复制元素 switch(_defaultconfig.direction) { default: case "top": _this.children().clone().appendto(_this); break; case "left": _this.css('width', _this.width() * 2); _this.children().clone().appendto(_this); break; case "right": _this.css('width', _this.width() * 2); _this.children().clone().prependto(_this); break; case "bottom": _this.children().clone().prependto(_this); break; } //循环移动 function loopmove() { var _currentoffset = 0, _height = _this.height(), _width = _this.width(), _offset = parseint(_this.css(_defaultconfig.direction)); switch(_defaultconfig.direction) { case 'top': case 'bottom': if (math.abs(_offset) - _height / 2 >= 0) { _this.css(_defaultconfig.direction, '0px'); } else { _this.css(_defaultconfig.direction, _offset - 1 + 'px'); } break; case 'left': case 'right': if (math.abs(_offset) - _width / 2 >= 0) { _this.css(_defaultconfig.direction, '0px'); } else { _this.css(_defaultconfig.direction, _offset - 1 + 'px'); } break; } } _this.hover(function() { clearinterval(_timer); }, function() { init(); }); function init() { _timer = setinterval(function() { loopmove(); }, _defaultconfig.speed); } init(); } }); })(jquery);