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