在普通javascript中将HTML元素的最高值作为整数获取

时间:2015-09-01 15:38:06

标签: javascript html css

我的网页上有一些HTML元素

<div id="element"></div>

我希望找出存储在

中的top
document.querySelector('div#element').style.top;

使用普通javascript作为整数。

2 个答案:

答案 0 :(得分:0)

如果您希望top属性为整数,请使用document.querySelector('div#element').offsetTop

答案 1 :(得分:0)

element=document.querySelector('#element')
parseInt(window.getComputedStyle(element,null).getPropertyValue('top'));