[英]Get the Y position of “position: fixed” element with pure javascript
有什么方法可以獲取在CSS中設置了“ position:fixed”的元素的當前Y位置? 我只需要知道使用純JavaScript的任何方式該元素與文檔頂部之間的距離即可。
如果這不可能,我想知道為什么在邏輯上不可能。
謝謝!
使用offsetTop
屬性。
var d = document.querySelector('div'); console.log(d.offsetTop);
div{ position:fixed; top:50px; background:red; width:50px; height:50px; }
<div> </div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.