码迷,mamicode.com
首页 > 编程语言 > 详细

【读书笔记】 通过原生javascript获取margin

时间:2015-07-30 16:36:22      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:

 

The properties on the style object are only the styles applied directly to the element (e.g., via a style attribute or in code). So .style.marginTop will only have something in it if you have something specifically assigned to that element (not assigned via a style sheet, etc.).

To get the current calculated style of the object, you use either the currentStyle property (Microsoft) or the getComputedStyle function (pretty much everyone else).

Example:

var p = document.getElementById("target");
var style = p.currentStyle || window.getComputedStyle(p);

display("Current marginTop: " + style.marginTop);

Fair warning: What you get back may not be in pixels. For instance, if I run the above on a pelement in IE9, I get back "1em".

【读书笔记】 通过原生javascript获取margin

标签:

原文地址:http://www.cnblogs.com/dhuhank/p/4689331.html

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