我只是想更好地构建我的 Javascript 并想知道如何将 window.onresize 合并到返回的对象中,如下所示:
var baseline = function(){
var tall, newHeight, target, imgl, cur, images = [];
return {
init: function(selector, target){
this.images = document.querySelectorAll(selector);
this.target = target;
this.setbase(this.images);
window.onresize = this.setbase(this.images);
},
setbase: function(imgs){
this.imgl = imgs.length;
if(this.imgl !== 0){
while(this.imgl--){
this.cur = imgs[this.imgl];
this.cur.removeAttribute("style");
this.tall = this.cur.offsetHeight;
this.newHeight = Math.floor(this.tall / this.target) * this.target;
this.cur.style.maxHeight = this.newHeight + 'px';
}
} else {
return false;
}
}
}
}();
这是人们会这样做的方式吗,这会奏效吗?谢谢
编辑:
像这样调用:
window.onload = function(){
baseline.init('img', '24');
};
我希望在调整窗口大小时,使用与初始 init 函数调用相同的参数调用baseline.init...