Fetch the repository succeeded.
import getVisualViewport from './getVisualViewport'
import getDocument from './getDocument'
import isLayoutViewport from './isLayoutViewport'
/**
* 获取 DOM 元素所在的文档的视口的尺寸
* ========================================================================
* @method getDocumentRect
* @since 1.8.0
* @param {HTMLElement} el
* @param {String} strategy
* @return {Object}
*/
const getViewportRect = (el, strategy) => {
const html = getDocument(el)
const visualViewport = getVisualViewport(el)
let width = html.clientWidth
let height = html.clientHeight
let x = 0
let y = 0
if (visualViewport) {
width = visualViewport.width
height = visualViewport.height
const layoutViewport = isLayoutViewport()
if (layoutViewport || (!layoutViewport && strategy === 'fixed')) {
x = visualViewport.offsetLeft
y = visualViewport.offsetTop
}
}
return {
width,
height,
x,
y
}
}
export default getViewportRect
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。