css的styleSheets模块

html-css05

css的styleSheets模块,第1张

1 .在css中,我们给属性设置值的时候,不需要考虑值的类型,但是在js中,必须为字符串(普通字符串,模板字符串),必须写全,声明中包含的单位必须完整的包含进去。

2 .想通过js设置css属性一定要查css名称对应的脚本属性。stylefloat

3 .style.cssText:获取所有的全部style属性

4 .getAttribute('style'):效果和上面等同

1 .修改元素的style属性

2 .修改元素的class或id

3 .插入样式标签

4 .改变页面的导入的样式表或者改变样式表

5 .className+='newClassName'

6 .className.replace(reg,'newClassName')

1 .app.style.width

1 .ie:app.currentStyle.width:

2 .document.defaultView.getComputedStyle(app,null).width:null-是否要取到伪类

3 .cssStyleSheet:获取一个页面引入的文件的数组

4 .cssStyleRuler:一个样式表里面所有的属性。

 用 gulp-replace 写个任务替换rem。

var replace = require('gulp-replace')

gulp.task('pxToRem', function(){

return gulp.src('*.html')

.pipe(replace(/(\d+)px/g, function(match, p1){

return Number(p1) / 10 + 'rem'

}))

.pipe(gulp.dest('dir'))

})

最简单的 就是给你看下原理 你可以自己修改

<span style="font-size:16px" onclick="this.style.fontSize=(parseInt(this.style.fontSize.replace('px',''))+2)+'px'">单击放大文字</span>

顺便说明parseInt是把字符串变数字 replace是把取得的css属性里的px去掉 原css里字体大小使用font-size控制 在js里对这种中间有横杠的都需要把横杠去掉并把第二个单词的首字母大写