You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
926 B
40 lines
926 B
7 years ago
|
function getScroll (w, top) {
|
||
|
let ret = top ? w.pageYOffset : w.pageXOffset
|
||
|
const method = top ? 'scrollTop' : 'scrollLeft'
|
||
7 years ago
|
if (typeof ret !== 'number') {
|
||
7 years ago
|
const d = w.document
|
||
7 years ago
|
// ie6,7,8 standard mode
|
||
7 years ago
|
ret = d.documentElement[method]
|
||
7 years ago
|
if (typeof ret !== 'number') {
|
||
|
// quirks mode
|
||
7 years ago
|
ret = d.body[method]
|
||
7 years ago
|
}
|
||
|
}
|
||
7 years ago
|
return ret
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
function getClientPosition (elem) {
|
||
|
let x
|
||
|
let y
|
||
|
const doc = elem.ownerDocument
|
||
|
const body = doc.body
|
||
|
const docElem = doc && doc.documentElement
|
||
|
const box = elem.getBoundingClientRect()
|
||
|
x = box.left
|
||
|
y = box.top
|
||
|
x -= docElem.clientLeft || body.clientLeft || 0
|
||
|
y -= docElem.clientTop || body.clientTop || 0
|
||
7 years ago
|
return {
|
||
|
left: x,
|
||
|
top: y,
|
||
7 years ago
|
}
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
export function getOffsetLeft (el) {
|
||
7 years ago
|
const pos = getClientPosition(el)
|
||
|
const doc = el.ownerDocument
|
||
|
const w = doc.defaultView || doc.parentWindow
|
||
|
pos.left += getScroll(w)
|
||
|
return pos.left
|
||
7 years ago
|
}
|