|
|
@ -147,16 +147,41 @@ $(function() { |
|
|
$(this).attr("aria-expanded", !isExpanded); |
|
|
$(this).attr("aria-expanded", !isExpanded); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
// Lenis.stop() 会 preventDefault 所有滚轮;面板需 data-lenis-prevent 才能内部滚动
|
|
|
|
|
|
|
|
|
// Lenis.stop() 会加 .lenis-stopped { overflow: clip },经典滚动条(如360)消失后
|
|
|
|
|
|
// fixed 头部会变宽;内容区通常不变。只补偿头部,不给 html/body 加 padding。
|
|
|
|
|
|
function getScrollbarWidth() { |
|
|
|
|
|
return Math.max(0, window.innerWidth - document.documentElement.clientWidth); |
|
|
|
|
|
} |
|
|
|
|
|
function lockPageScroll() { |
|
|
|
|
|
const root = document.documentElement; |
|
|
|
|
|
if (root.classList.contains("is-scroll-locked")) return; |
|
|
|
|
|
const sbw = getScrollbarWidth(); |
|
|
|
|
|
root.style.setProperty("--scroll-lock-compensation", `${sbw}px`); |
|
|
|
|
|
root.classList.add("is-scroll-locked"); |
|
|
|
|
|
lenis.stop(); |
|
|
|
|
|
// 若 CSS 已保住滚动条,则清零补偿,避免头部被多余收窄
|
|
|
|
|
|
requestAnimationFrame(() => { |
|
|
|
|
|
if (getScrollbarWidth() > 0) { |
|
|
|
|
|
root.style.setProperty("--scroll-lock-compensation", "0px"); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
function unlockPageScroll() { |
|
|
|
|
|
const root = document.documentElement; |
|
|
|
|
|
if (!root.classList.contains("is-scroll-locked")) return; |
|
|
|
|
|
root.classList.remove("is-scroll-locked"); |
|
|
|
|
|
root.style.removeProperty("--scroll-lock-compensation"); |
|
|
|
|
|
lenis.start(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
$(".nav-mega").attr("data-lenis-prevent", ""); |
|
|
$(".nav-mega").attr("data-lenis-prevent", ""); |
|
|
|
|
|
|
|
|
// hover 展开 mega 面板时禁止/恢复页面滚动
|
|
|
|
|
|
$(".site-header__nav-item--mega").on("mouseenter", function() { |
|
|
$(".site-header__nav-item--mega").on("mouseenter", function() { |
|
|
if ($("body").hasClass("is-mask-open")) return; |
|
|
if ($("body").hasClass("is-mask-open")) return; |
|
|
lenis.stop(); |
|
|
|
|
|
|
|
|
lockPageScroll(); |
|
|
}).on("mouseleave", function() { |
|
|
}).on("mouseleave", function() { |
|
|
if ($("body").hasClass("is-mask-open")) return; |
|
|
if ($("body").hasClass("is-mask-open")) return; |
|
|
lenis.start(); |
|
|
|
|
|
|
|
|
unlockPageScroll(); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
//#endregion
|
|
|
//#endregion
|