3 Star 54 Fork 14

Yaohaixiao / dom.js

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
getPageX.js 885 Bytes
一键复制 编辑 原始数据 按行查看 历史
import isElement from './isElement'
import getDocumentScrollLeft from './getDocumentScrollLeft'
import canPosition from './canPosition'
/**
* 基于页面坐标获取元素的当前 X 位置。
* ========================================================================
* @method getPageX
* @see https://developer.mozilla.org/zh-CN/docs/Web/API/Node/ownerDocument
* @param {HTMLElement} el
* @return {Number|Boolean}
*/
const getPageX = (el) => {
const floor = Math.floor
let scrollLeft
let box
let doc
let pageX
/* istanbul ignore else */
if (!isElement(el) || !canPosition(el)) {
return false
}
box = el.getBoundingClientRect()
doc = el.ownerDocument
scrollLeft = getDocumentScrollLeft(doc)
pageX = floor(box.left)
if (scrollLeft) {
pageX += scrollLeft
}
return pageX
}
export default getPageX
JavaScript
1
https://gitee.com/yaohaixiao/dom.js.git
git@gitee.com:yaohaixiao/dom.js.git
yaohaixiao
dom.js
dom.js
main

搜索帮助