📌  相关文章
📜  div 元素在屏幕中的位置 - C# 代码示例

📅  最后修改于: 2022-03-11 14:48:54.796000             🧑  作者: Mango

代码示例1
function offset(el) {    var rect = el.getBoundingClientRect(),    scrollLeft = window.pageXOffset || document.documentElement.scrollLeft,    scrollTop = window.pageYOffset || document.documentElement.scrollTop;    return { top: rect.top + scrollTop, left: rect.left + scrollLeft }}
// example usevar div = document.querySelector('div');var divOffset = offset(div);console.log(divOffset.left, divOffset.top);