getDomPosition (dom) {
if (dom) {
return Array.from(dom).map(node => {
let style = null
if (window.getComputedStyle) {
style = window.getComputedStyle(node, null) // 非IE
} else {
style = node.currentStyle // IE
}
const { top: t, left: l } =
node.getBoundingClientRect() || {}
// const top = parseInt(node.offsetTop, 10); //相对于父元素
// const left = parseInt(node.offsetLeft, 10); //相对于父元素
const top = parseInt(t, 10) // 相对于窗口
const left = parseInt(l, 10) // 相对于窗口
const width = parseInt(style.width, 10)
const height = parseInt(style.height, 10)
return { left, top, width, height }
})
} else {
return []
}
},