javascript之脚本化css

通过js给dom样式

dom.style.prop

关键字 float前面加css
例如: dom.style.cssFloat

查询计算样式
window.getComputedStyle(ele, null)
IE8及以下不兼容
获取伪元素的样式 window.getComputedStyle(ele, before/after)

ele.currentStyle
IE的方法

封装兼容性写法 getStyle(ele, prop)

function getStyle(ele, prop) {
  if(window.getComputedStyle) {
    return window.getComputedStyle(ele, null)[prop]
  }else {
    return ele.currentStyle[prop]
  }
}

end !!!

原文地址:https://www.cnblogs.com/lyjfight/p/13830354.html