currentStyle、getComputedStyle

element.offsetWidth:chrome

返回元素的宽度,包括边框和内边距。浏览器

element.offsetHeight:spa

返回元素的高度,包括边框和内边距。code

currentStyle:对象

获取计算后的样式,也叫当前样式、最终样式。优势:能够获取元素的最终样式,包括浏览器的默认值,而不像style只能获取行间样式,因此更经常使用到。注意:不能获取复合样式如background属性值,只能获取单同样式如background-color等。currentStyle ie、opera上是可行的,没法适用于全部浏览器的。blog


getComputedStyle( obj , false ): element

是支持 w3c (FF十二、chrome 1四、safari):在FF新版本中只须要第一个参数,即操做对象,第二个参数写“false”也是你们通用的写法,目的是为了兼容老版本的火狐浏览器。
因此能够这样来写兼容:get

1 var obj= document.getElmentById("id");
2 var getStyle = function (obj,attr) {
3         if(obj.currentStyle){
4                //
5               return  parseInt(obj.currentStyle[attr]);
6           }else{
7               return parseInt(getComputedStyle(obj,false)[attr]);      
8          }
9 }
相关文章
相关标签/搜索