function fetchComputedStyle( obj , property) {
if (window.getComputedStyle){
//把用户输入的property检测是不是驼峰,如果是,转为连字符
// 转为连字符的方法 :强制把用户输入的大写字母,变成小写字母加-
// paddingLeft -> padding-left
property = property.replace(/([A-Z])/,function (match,$1) {
return "-" + $1.toLowerCase();
});
return window.getComputedStyle(obj)[property];
}else {
//IE只认识驼峰,要防止用户输入短横,所以需把短横改为大写字母
//padding-left -> paddingLeft
property = property.replace(/\-(a-z)/,function (match,$1) {
return $1.toUpperCase();
});
return obj.currentStyle[property];
}
}
得到计算后样式兼容性代码
最新推荐文章于 2021-05-21 16:55:42 发布