util.js
1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getOffsetLeft = getOffsetLeft;
/* eslint-disable import/prefer-default-export */
function getScroll(w) {
var ret = w.pageXOffset;
var method = 'scrollLeft';
if (typeof ret !== 'number') {
var d = w.document; // ie6,7,8 standard mode
ret = d.documentElement[method];
if (typeof ret !== 'number') {
// quirks mode
ret = d.body[method];
}
}
return ret;
}
function getClientPosition(elem) {
var x;
var y;
var doc = elem.ownerDocument;
var body = doc.body;
var docElem = doc && doc.documentElement;
var box = elem.getBoundingClientRect();
x = box.left;
y = box.top;
x -= docElem.clientLeft || body.clientLeft || 0;
y -= docElem.clientTop || body.clientTop || 0;
return {
left: x,
top: y
};
}
function getOffsetLeft(el) {
var pos = getClientPosition(el);
var doc = el.ownerDocument; // Only IE use `parentWindow`
var w = doc.defaultView || doc.parentWindow;
pos.left += getScroll(w);
return pos.left;
}