Ohm-Management - Projektarbeit B-ME
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.

util.js 1.2KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Return target's cumulative offset from the top
  2. export function getOffset(target) {
  3. if (typeof target === 'number') {
  4. return target;
  5. }
  6. var el = $(target);
  7. if (!el) {
  8. throw typeof target === 'string' ? new Error('Target element "' + target + '" not found.') : new TypeError('Target must be a Number/Selector/HTMLElement/VueComponent, received ' + type(target) + ' instead.');
  9. }
  10. var totalOffset = 0;
  11. while (el) {
  12. totalOffset += el.offsetTop;
  13. el = el.offsetParent;
  14. }
  15. return totalOffset;
  16. }
  17. export function getContainer(container) {
  18. var el = $(container);
  19. if (el) return el;
  20. throw typeof container === 'string' ? new Error('Container element "' + container + '" not found.') : new TypeError('Container must be a Selector/HTMLElement/VueComponent, received ' + type(container) + ' instead.');
  21. }
  22. function type(el) {
  23. return el == null ? el : el.constructor.name;
  24. }
  25. function $(el) {
  26. if (typeof el === 'string') {
  27. return document.querySelector(el);
  28. } else if (el && el._isVue) {
  29. return el.$el;
  30. } else if (el instanceof HTMLElement) {
  31. return el;
  32. } else {
  33. return null;
  34. }
  35. }
  36. //# sourceMappingURL=util.js.map