码迷,mamicode.com
首页 > 其他好文 > 详细

document.defaultView.getComputedStyle

时间:2015-11-08 22:27:44      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:

我们在使用js过程中,有时候需要获取对象的宽度,如果对象本身是由内容撑开。宽度未知的情况,有一个强大的方法document.defaultView.getComputedStyle()可以获取对象的css样式;他返回的是一个CSS样式对象。

使用:document.defaultView.getComputedStyle(a, b);
a这对象是要想要获取的对象。
b,伪类,若果不是则为null。
div{     width: 100px;     font-size: 15px; }
<div>遇见他,她变得很低很低,低到尘里,可她心里是欢喜的,从尘埃里开出花来</div>
var d=document.getElementsByTagName("div")[0]; 
console.log(document.defaultView.getComputedStyle(d,null).height);
console.log(document.defaultView.getComputedStyle(d,null).fontSize);

document.defaultView.getComputedStyle

标签:

原文地址:http://www.cnblogs.com/yangjinfeng172/p/4948139.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!