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.

index.js 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  2. import * as easingPatterns from './easing-patterns';
  3. import { getContainer, getOffset } from './util';
  4. import Vue from 'vue';
  5. export default function goTo(_target) {
  6. var _settings = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  7. var settings = _extends({
  8. container: document.scrollingElement || document.body || document.documentElement,
  9. duration: 500,
  10. offset: 0,
  11. easing: 'easeInOutCubic',
  12. appOffset: true
  13. }, _settings);
  14. var container = getContainer(settings.container);
  15. if (settings.appOffset) {
  16. var isDrawer = container.classList.contains('v-navigation-drawer');
  17. var isClipped = container.classList.contains('v-navigation-drawer--clipped');
  18. settings.offset += Vue.prototype.$vuetify.application.bar;
  19. if (!isDrawer || isClipped) settings.offset += Vue.prototype.$vuetify.application.top;
  20. }
  21. var startTime = performance.now();
  22. var targetLocation = getOffset(_target) - settings.offset;
  23. var startLocation = container.scrollTop;
  24. if (targetLocation === startLocation) return Promise.resolve(targetLocation);
  25. var ease = typeof settings.easing === 'function' ? settings.easing : easingPatterns[settings.easing];
  26. if (!ease) throw new TypeError('Easing function "' + settings.easing + '" not found.');
  27. // tslint:disable-next-line:promise-must-complete
  28. return new Promise(function (resolve) {
  29. return requestAnimationFrame(function step(currentTime) {
  30. var timeElapsed = currentTime - startTime;
  31. var progress = Math.abs(settings.duration ? Math.min(timeElapsed / settings.duration, 1) : 1);
  32. container.scrollTop = Math.floor(startLocation + (targetLocation - startLocation) * ease(progress));
  33. if (progress === 1 || container.clientHeight + container.scrollTop === container.scrollHeight) {
  34. return resolve(targetLocation);
  35. }
  36. requestAnimationFrame(step);
  37. });
  38. });
  39. }
  40. //# sourceMappingURL=index.js.map