代码拉取完成,页面将自动刷新
import isElement from './isElement'
import isLayoutViewport from './isLayoutViewport'
import getVisualViewport from './getVisualViewport'
/**
* 获取 DOM 元素的 getBoundingClientRect 数据
* ========================================================================
* @method getBoundingClientRect
* @since 1.7.0
* @see https://github.com/floating-ui/floating-ui
* @param {HTMLElement} el
* @param {Boolean} [includeScale]
* @param {Boolean} [isFixedStrategy]
* @return {Object}
*/
const getBoundingClientRect = (
el,
includeScale = false,
isFixedStrategy = false
) => {
const round = Math.round
const clientRect = el.getBoundingClientRect()
const visualViewport = getVisualViewport(el)
const addVisualOffsets = !isLayoutViewport() && isFixedStrategy
let scaleX = 1
let scaleY = 1
if (includeScale && isElement(el)) {
let offsetWidth = el.offsetWidth
let offsetHeight = el.offsetHeight
scaleX = offsetWidth > 0 ? round(clientRect.width) / offsetWidth || 1 : 1
scaleY = offsetHeight > 0 ? round(clientRect.height) / offsetHeight || 1 : 1
}
const x =
(clientRect.left +
(addVisualOffsets ? visualViewport?.offsetLeft ?? 0 : 0)) /
scaleX
const y =
(clientRect.top + (addVisualOffsets ? visualViewport?.offsetTop ?? 0 : 0)) /
scaleY
const width = clientRect.width / scaleX
const height = clientRect.height / scaleY
return {
width,
height,
top: y,
right: x + width,
bottom: y + height,
left: x,
x,
y
}
}
export default getBoundingClientRect
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。