9ab000bc4bb695f157388147a5f5353541fb8a1ef4a7fa774fefbb6fc814d7c6613e98ff82b08b214ca52ac621c10ce85fb91058b1f00f73f3dd3daebdb7d7 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var core = require('@vueuse/core');
  5. var error = require('../../../utils/error.js');
  6. const useBackTop = (props, emit, componentName) => {
  7. const el = vue.shallowRef();
  8. const container = vue.shallowRef();
  9. const visible = vue.ref(false);
  10. const handleScroll = () => {
  11. if (el.value)
  12. visible.value = el.value.scrollTop >= props.visibilityHeight;
  13. };
  14. const handleClick = (event) => {
  15. var _a;
  16. (_a = el.value) == null ? void 0 : _a.scrollTo({ top: 0, behavior: "smooth" });
  17. emit("click", event);
  18. };
  19. const handleScrollThrottled = core.useThrottleFn(handleScroll, 300, true);
  20. core.useEventListener(container, "scroll", handleScrollThrottled);
  21. vue.onMounted(() => {
  22. var _a;
  23. container.value = document;
  24. el.value = document.documentElement;
  25. if (props.target) {
  26. el.value = (_a = document.querySelector(props.target)) != null ? _a : void 0;
  27. if (!el.value) {
  28. error.throwError(componentName, `target does not exist: ${props.target}`);
  29. }
  30. container.value = el.value;
  31. }
  32. handleScroll();
  33. });
  34. return {
  35. visible,
  36. handleClick
  37. };
  38. };
  39. exports.useBackTop = useBackTop;
  40. //# sourceMappingURL=use-backtop.js.map