3 Star 56 Fork 13

Yaohaixiao/dom.js

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
getViewportRect.js 989 Bytes
Copy Edit Raw Blame History
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
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/yaohaixiao/dom.js.git
git@gitee.com:yaohaixiao/dom.js.git
yaohaixiao
dom.js
dom.js
main

Search

Cb406eda 1850385 E526c682 1850385