!(function(global, $, factory) { typeof exports == "object" && typeof module != "undefined" ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (global.ResizeScroll = factory()); })(this, jQuery, function() { var ResizeScroll = function(options) { if (!(this instanceof ResizeScroll)) { console.log("ResizeScroll 是一个构造函数,应该用new关键字调用"); return; } var _DEFALUTS_ = { "id" : "", //必填,如果是id就写#id,如果是class名,就写.class "index" : "", "fun" : function() {}, "height" : "100%", "time" : "100", "alwaysVisible" : false } $.extend(true, _DEFALUTS_, options || {}); function AutoScroll() { var reheight = _DEFALUTS_.fun && _DEFALUTS_.fun(); var _body; if (_DEFALUTS_.index != "") { _body = $(_DEFALUTS_.id).eq(_DEFALUTS_.index); } else { _body = $(_DEFALUTS_.id); } //先进行销毁,防止重复生成 _body.slimScroll({ destroy : true }); _body.slimScroll({ height : reheight || _DEFALUTS_.height, railOpacity : .9, alwaysVisible : _DEFALUTS_.alwaysVisible }); } this.scrollFun = AutoScroll; var _this = this; $(window).resize(function() { var handleResize = function() { // The timer kid if (_this.kid) { window.clearTimeout(_this.kid); _this.kid = null; } _this.kid = window.setTimeout(function() { _this.scrollFun(); }, _DEFALUTS_.time); }; handleResize(); }); this.scrollFun(); } return ResizeScroll; })