@flexilla/utilities
Version:
Utilities package for flexilla library
17 lines (16 loc) • 629 B
JavaScript
import { $ as t } from "./selector.js";
const p = ({ triggerElement: e, initFrom: i = 300, target: s }) => {
const o = typeof e == "string" ? t(e) : e, l = typeof s == "string" ? t(s) : s, c = l || window, n = () => {
o == null || o.setAttribute("data-state", window.scrollY > i ? "visible" : "hidden");
}, r = () => {
c.scrollTo({ top: 0, behavior: "smooth" });
};
return c.addEventListener("scroll", n), o == null || o.addEventListener("click", r), {
cleanup: () => {
c.removeEventListener("scroll", n), o == null || o.removeEventListener("click", r);
}
};
};
export {
p as initScrollToTop
};