|
|
!(function (global, $, factory) {
|
|
typeof exports == "object" && typeof module != "undefined" ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (global.CustomResize = factory());
|
})(this, jQuery, function () {
|
|
var CustomResize = function (options) {
|
if (!(this instanceof CustomResize)) {
|
console.log("CustomResize 是一个构造函数,应该用new关键字调用");
|
return;
|
}
|
|
var _DEFALUTS_ = {
|
"id": "", //必填,如果是id就写#id,如果是class名,就写.class
|
"index":"", //如果class有好几个,需要确定某一个
|
"fun":function(){
|
},
|
"height":"100%",
|
"time":"100",
|
"needFirstLoadFun":true //有的时候位置不对,不需要加载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.height(reheight||_DEFALUTS_.height)
|
|
|
}
|
|
this.resizeFun= 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.resizeFun();
|
|
}, _DEFALUTS_.time);
|
};
|
|
handleResize();
|
|
});
|
|
_DEFALUTS_.needFirstLoadFun && this.resizeFun();
|
}
|
|
return CustomResize;
|
|
})
|