开发者

when to use elem.style.left o r elem.offsetLeft

开发者 https://www.devze.com 2023-01-26 03:24 出处:网络
When you are trying to get the left valu开发者_Python百科e of an element, what is the difference between elem.style.left or elem.offsetLeft in javascript? the difference is that elem.offsetLeft is a c

When you are trying to get the left valu开发者_Python百科e of an element, what is the difference between elem.style.left or elem.offsetLeft in javascript?


the difference is that elem.offsetLeft is a computed value of left offset, calculated by browser even if you haven't specified explictly the same property via style and/or CSS, instead elem.style.left it's a get of property left of style attribute

try this code: http://jsfiddle.net/nnryG/

the computedValue is unitless, the style property is what you assigned in inline style.

0

精彩评论

暂无评论...
验证码 换一张
取 消