Get and set the top and left values of an element

The first method, which is relatively simple, is to directly pass obj.style.left and obj.style.top, but there are limitations. This method of obtaining can only obtain the property values ​​of left and top of the inline style, but cannot obtain it. The left and top property values ​​of style tags and link external references.

The second method is read-only and can get all styles. There is a compatibility problem. In standard browsers, you can use the window.getComputedStyle(object, null).left method to get the left and top property values ​​of the element. On the IE browser, the obj.currentStyle.left method is used to obtain the property value. Both ways are read-only.

The third method, use obj.offsetLeft to get the left property value of the object, and use obj.offsetTop to get the top property value of the object.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324778738&siteId=291194637