Computed Styles

 

The style object offers no information about the styles that have cascaded from style sheets and affect the element. DOM Level 2 provide a method called getComputedStyle(). This method accepts two arguments: the element to get the computed style for and a pseudo-element string (such as ":after"). The second argument can be null if no pseudo-element information is necessary.  IE doesn't support getComputedStyle(), though it has a similar concept. Every element that has a style property also has a currentStyle property.

1 function getStyle(obj, name) {
2     if (obj.currentStyle) { 
3         return obj.currentStyle[name];
4     } else {
5         return getComputedStyle(obj, null)[name];
6     }
7 }    

 

posted @ 2015-06-06 16:26  林大勇  阅读(234)  评论(0编辑  收藏  举报