pure JavaScript scripts get element styles
One, the problem description
Sometimes, we need to do some of the pages to adapt the elements according to different display, then how to calculate the margin-top of this element, I believe that everyone will calculate, then involved in one is to use JS to get this element of the style, such as height
Two, Solution
As we all know, for an HTML page element, its style definition has two ways, one is written in the elements of the peer node, commonly known as the inline style, the other is defined in the external CSS file, commonly known as the external style, that is, these two definitions, resulting in the way we get height differences, See the table below
var obj = document.getElementById ("The value of the id attribute of your page element");
How to get there description
obj.offsetheight offsetxxx Ignore inline or out-of-line style, so this method gets a wide range than the next one
obj.style.height Obj.style.XXX This method is only suitable for inline styles
Pure JavaScript Gets the height and width of an element