window.getComputedStyle
来源:互联网 发布:iphone8知乎 编辑:程序博客网 时间:2024/06/16 12:07
window.getComputedStyle(元素,伪类)
用于获得元素最终使用的css属性值,返回一个实时的 CSSStyleDeclaration,只读。
var dom = document.getElementById("test"), style = window.getComputedStyle(dom);
getComputedStyle与style的区别:
getComputedStyle读取的结果是只读的,
而el.style可以用于设置元素样式getComputedStyle方法获取的是最终应用在元素上的所有CSS属性对象
而el.style只能获取元素style属性中的CSS样式
另外还有IE中支持的elcurrentStyle,返回元素最终的所有属性,包括外链和style标签中的样式。
以上三种方法都会返回CSSStyleDeclaration对象,表示一个CSS属性键值对的集合。这个对象拥有以下属性与方法:
- 属性:
- cssText:文本内容,可以提供样式字符串来设定样式
- length:属性的数量
- 方法:
- getPropertyValue(属性名):获取属性值
- removeProperty()
- setProperty()
总结
与jQuery这种库相比,getComputedStyle最优秀的用途就是可以获取伪类元素样式。
阅读全文
0 0
- window.getComputedStyle
- window.getComputedStyle详解
- window.getComputedStyle()方法的使用
- javascript获取元素CSS值window.getComputedStyle
- 实现浏览器兼容版的window.getComputedStyle
- getComputedStyle
- getComputedStyle
- getComputedStyle
- getComputedStyle
- JavaScript--window与document的getComputedStyle()方法的区别
- window.getComputedStyle() returns null inside an iframe with display: none
- 如何实现浏览器兼容版的window.getComputedStyle
- 火狐浏览器 window.getComputedStyle()返回值的问题
- currentStyle、getComputedStyle
- getComputedStyle && currentStyle
- javascipt:getComputedStyle()
- getComputedStyle无伪类
- getComputedStyle有伪类
- leetcode 334. Increasing Triplet(三连) Subsequence
- Miller Rabbin 大素数测试
- SpringMVC异常处理使用@ControllerAdvice注释
- 移动端关于点击输入框,因字体变化,导致布局变形的问题
- 极客学院 Mybatis 与 Spring3 集成 完整applicationContext.xml
- window.getComputedStyle
- hdu6105
- Android-ShimmerLayout微光效果解析
- Weblogic10.3及以上版本的下载地址
- 炬力V100遇到问题及解决
- 写给希望让计算机成为自己的高级玩具的高阶玩家
- 国人开发的一套免费开源图标库 草莓图标库
- 一步一步制作yaffs/yaffs2根文件系统(一)---储备好基础知识再打
- 图像处理常用算法GPU实现二:基于微分的边缘检测