dom操作,计算元素距离document顶部高度
2020-06-24 本文已影响0人
瓢鳍小虾虎
function getOffset (node) {
let result = {
top: 0,
left: 0
}
if (!node.getClientRects().length) {
return;
}
if (window.getComputedStyle(ele)['display'] === 'none') {
return result
}
result = node.getBoundingClientRect()
var docElement = node.ownerDocument.documentElement
return {
top: result.top + window.pageYOffset - docElement.clientTop,
left: result.left + window.pageXOffset - docElement.clientLeft
}
}