【JS】- 获取元素在浏览器中的位置
// 获取元素坐标 - left getElementPageLeft(element) { var actualLeft = element.offsetLeft; var parent = element.offsetParent; while (parent != null) { actualLeft += parent.offsetLeft + parent.clientLeft; parent = parent.offsetParent; } return actualLeft; }, // 获取元素坐标 - top getElementPageTop(element) { var actualTop = element.offsetTop; var parent = element.offsetParent; while (parent != null) { actualTop += parent.offsetTop + parent.clientTop; parent = parent.offsetParent; } return actualTop; }