function wormInnerAttr(options) { for (var i in options) this[i] = options[i] this.update = function() { $(this.el).each(function(index, item) { console.log(item); $(item).css(this.attr, ($(window).width() * this.scale) + this.unit) }.bind(this)) } this.update.call(this) window.addEventListener('resize', this.update.bind(this), false) } // new wormInnerAttr({ // el: '', // 元素 // scale: 0.8, // 比例 // unit: 'px', // 单位 // attr: 'padding' // css属性 // })