封装获取行间样式及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)

  

posted @ 2020-08-08 09:27  菜鸟程序员的总结  阅读(263)  评论(0编辑  收藏  举报