封装的调整样式

(function(win,doc){
    var defaultSettings={
        color:'red',
        background:'blue',
        border:'2px solid #ddd',
        fontSize:'30px',
        testAlign:'center',
        width:'200px',
        borderRadius:'5px'
    }
    function SetStyles(options){
        var self=this;
        if(!options){
            throw new Error("请传入配置参数")
        }
        self=Object.assign(self,defaultSettings,options);
        self.container=doc.querySelector(self.container)||doc.querySelectorAll(self.container);
        self._changeStyles();
    }
    SetStyles.prototype={
        _changeStyles:function(){
            var self=this;
            for(var pro in self){
                if(pro == 'container'){
                    continue;
                }
                if(pro=='text'&&typeof self[pro]=='string'){
                    self.container.innerText=self[pro];
                    continue;
                }else if(pro=='text'&&typeof self[pro]=='function'){
                    self.container.innerText=self[pro]()
                }
                self.container.style[pro]=self[pro];
            }
        }
        
    }
    win.SetStyles=SetStyles;
})(windows,document)

你可能感兴趣的:(js,css,函数,闭包)