util.js 1.0 KB

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