3 Star 54 Fork 14

Yaohaixiao / dom.js

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
inBounding.js 777 Bytes
一键复制 编辑 原始数据 按行查看 历史
Yaohaixiao 提交于 2023-10-12 16:04 . chore: 调整单测代码
import isElement from './isElement'
/**
* 检测某个 DOM 节点的位置是否在另个一个 DOM 节点范围内
* ========================================================================
* @method inBounding
* @param {HTMLElement} child
* @param {HTMLElement} parent
* @return {Boolean}
*/
const inBounding = (child, parent) => {
let parentRect
let childRect
if (!isElement(child) || !isElement(parent)) {
return false
}
parentRect = parent.getBoundingClientRect()
childRect = child.getBoundingClientRect()
return (
childRect.top >= parentRect.top &&
childRect.right <= parentRect.right &&
childRect.bottom <= parentRect.bottom &&
childRect.left >= parentRect.left
)
}
export default inBounding
JavaScript
1
https://gitee.com/yaohaixiao/dom.js.git
git@gitee.com:yaohaixiao/dom.js.git
yaohaixiao
dom.js
dom.js
main

搜索帮助

53164aa7 5694891 3bd8fe86 5694891