[英]Get top value for HTML element as an integer in plain javascript
I have some HTML element on my page我的页面上有一些 HTML 元素
<div id="element"></div>
and I would like to find out its top
value as stored in我想找出它存储在的
top
值
document.querySelector('div#element').style.top;
as an integer using plain javascript.作为使用普通javascript的整数。
如果您希望 top 属性为整数,请使用document.querySelector('div#element').offsetTop
。
element=document.querySelector('#element')
parseInt(window.getComputedStyle(element,null).getPropertyValue('top'));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.