首页 > Web开发 > 详细

zepto 的 css 方法 -- 待续

时间:2017-03-01 14:33:29      阅读:405      评论:0      收藏:0      [点我收藏+]

链接

 

获取样式: 

 getComputedStyle  什么是计算后的样式

 就是经过css样式组合 和 js操作后 的 最后的结果

 

设置样式有三种方法:

 
div.style.backgroundColor = "red"
 
div.style.setProperty(‘background-color‘,‘green‘)

div.style.cssText += ";background-color:red;";

 

删除相应的样式


div.style.removeProperty(‘background-color‘)

 

如何转为驼峰

‘background-color‘  -- >  backgroundColor

var cameLize = function(str) {


        return str.replace(/-+(.)?/g, function(match, chr) {

      //chr 就是 (.)  也就是 c, 因为前面一定有一个 -

      // 先判断chr有没有, 以免后面报错

      // match 这里是整体匹配到了 -c , 但是最后只取了子项, 并转为大写后返回 , 所以 -c 会被替换成 C


                return chr ? chr.toUpperCase() : "";

      
        });


};

 

关键正则理解

 

‘/aaABBcdefH1g3Ggg‘.replace(/([A-Z]+)([A-Z][a-z])/g, ‘$1_$2‘);

 $1是AB  $2是Bc 


而不是  aaABBcdefH  和 g ,

 

zepto 的 css 方法 -- 待续

原文:http://www.cnblogs.com/dhsz/p/6483874.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!