asp-smart-ui-plus-test
Version:
A Component Library for Vue 3
19 lines (17 loc) • 599 B
JavaScript
function preventScroll(flag) {
if (flag) {
const top = document.documentElement.scrollTop || document.body.scrollTop || 0;
document.body.style.position = "fixed";
document.body.style.width = "100vw";
document.body.style.overflow = "hidden";
document.body.style.left = "0";
document.body.style.top = `-${top}px`;
} else {
const top = document.body.style.top;
document.body.style.position = "static";
document.body.style.overflow = "";
window.scrollTo(0, Math.abs(Number.parseFloat(top)));
document.body.style.top = "";
}
}
export { preventScroll };