@dfsj/ec-hooks
Version:
贵州东方世纪常用 hook。
28 lines (27 loc) • 767 B
JavaScript
import { shallowRef as f, watch as m, readonly as I } from "vue";
import { useIntersection as b } from "./useIntersection.js";
function w(o, s = o[0]) {
const e = f(s), { setScrollContainer: c, stopScrollLocation: r, firstVisible: i, isScrollEnd: a } = b(o);
return m([i, a], ([t, l]) => {
l ? e.value = o[o.length - 1] : e.value = t;
}), {
setScrollContainer: c,
firstVisibleId: I(e),
stopScrollLocation: r,
scrollInto: u
};
function u(t) {
const l = document.getElementById(t);
return e.value = t, r(), new Promise((n) => {
setTimeout(() => {
l || n(!1), l.scrollIntoView({
behavior: "smooth",
block: "start"
}), n(!0);
}, 60);
});
}
}
export {
w as useScrollLocation
};