tass-ui
Version:
A high quality UI Toolkit built on Vue.js3+.
48 lines (47 loc) • 1.63 kB
JavaScript
;
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const vue = require("vue");
require("../../../theme-chalk/src/backtop.scss.js");
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
__name: "backtop",
setup(__props) {
const btnShow = vue.ref(true);
vue.onMounted(() => {
window.addEventListener("scroll", scrollToTop);
window.addEventListener("beforeunload", (e) => {
window.scroll(0, 0);
});
});
let timer = null;
function backTop() {
timer = setInterval(function() {
let backTop2 = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
let speedTop = backTop2 / 10;
document.documentElement.scrollTop = backTop2 - speedTop;
if (Math.abs(backTop2) < 1) {
clearInterval(timer);
}
}, 10);
}
function scrollToTop() {
let pageLookHeight = document.documentElement.clientHeight || document.body.clientHeight;
let scroll = document.documentElement.scrollTop;
btnShow.value = scroll >= pageLookHeight * 0.01;
}
return (_ctx, _cache) => {
const _component_tass_icon = vue.resolveComponent("tass-icon");
return vue.withDirectives((vue.openBlock(), vue.createElementBlock("div", {
class: "tas-backtop",
onClick: backTop
}, [
vue.createVNode(_component_tass_icon, {
name: "rocket",
class: "tas-backtop-icon"
})
], 512)), [
[vue.vShow, btnShow.value]
]);
};
}
});
exports.default = _sfc_main;