封装获取行间样式及getComputedStyle不为人知的秘密
function getStyle(ele,prop){
if(window.getComputedStyle){ //w3c标准 return window.getComputedStyle(ele,null)[prop]; }else{//ie低版本 return ele.currentStyle[prop]; } }
对于工作中碰到的伪元素的操作可以getComputedStyle来解决,就是第二个参数null可以直接填写after,进行了二次封装
function getStyle(ele,prop,af){
if(window.getComputedStyle){ //w3c标准
if(prop==''){
return window.getComputedStyle(ele,af);
}else{
return window.getComputedStyle(ele,null)[prop];
}
}else{//ie低版本
return ele.currentStyle[prop];
}
}
console.log(getStyle(div,'','after').width)

浙公网安备 33010602011771号