util.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.getMotionName = getMotionName;
  6. exports.getUUID = getUUID;
  7. exports.offset = offset;
  8. // =============================== Motion ===============================
  9. function getMotionName(prefixCls, transitionName, animationName) {
  10. let motionName = transitionName;
  11. if (!motionName && animationName) {
  12. motionName = `${prefixCls}-${animationName}`;
  13. }
  14. return motionName;
  15. }
  16. // ================================ UUID ================================
  17. let uuid = -1;
  18. function getUUID() {
  19. uuid += 1;
  20. return uuid;
  21. }
  22. // =============================== Offset ===============================
  23. function getScroll(w, top) {
  24. let ret = w[`page${top ? 'Y' : 'X'}Offset`];
  25. const method = `scroll${top ? 'Top' : 'Left'}`;
  26. if (typeof ret !== 'number') {
  27. const d = w.document;
  28. ret = d.documentElement[method];
  29. if (typeof ret !== 'number') {
  30. ret = d.body[method];
  31. }
  32. }
  33. return ret;
  34. }
  35. function offset(el) {
  36. const rect = el.getBoundingClientRect();
  37. const pos = {
  38. left: rect.left,
  39. top: rect.top
  40. };
  41. const doc = el.ownerDocument;
  42. const w = doc.defaultView || doc.parentWindow;
  43. pos.left += getScroll(w);
  44. pos.top += getScroll(w, true);
  45. return pos;
  46. }