获取元素自身的宽高和top等
export function getRect(obj) {
if (obj) {
var xy = obj.getBoundingClientRect()
var top =
xy.top -
document.documentElement.clientTop +
document.documentElement.scrollTop, //document.documentElement.clientTop 在IE67中始终为2,其他高级点的浏览器为0
bottom = xy.bottom,
left =
xy.left -
document.documentElement.clientLeft +
document.documentElement.scrollLeft, //document.documentElement.clientLeft 在IE67中始终为2,其他高级点的浏览器为0
right = xy.right,
width = xy.width || right - left, //IE67不存在width 使用right - left获得
height = xy.height || bottom - top
return {
top: top,
right: right,
bottom: bottom,
left: left,
width: width,
height: height,
}
}
}
使用:
import { getRect } from "~/plugins/common"
let { top } = getRect(this.$refs.selectdom)
dfd