vivid 手机端顶栏下滑自动隐藏:滚过 80px 向下滑收起、向上滑或回页首即回现,2px 抖动过滤,抽屉打开期间强制可见
This commit is contained in:
1 parent
00e85bf667
commit
e5dee4daf1
2 files changed
+23
-4
No files matched your search
@@ -26,6 +26,10 @@ const scrolled = ref(false)
|
||||
const menuOpen = ref(false)
|
||||
const burger = ref(null)
|
||||
const drawerEl = ref(null)
|
||||
// 手机端顶栏:向下滑动藏起来给内容让路,向上一滑就回来。
|
||||
// 抽屉开着时不藏——汉堡就是 ✕,藏了就没法关菜单。
|
||||
const barHidden = ref(false)
|
||||
let lastY = 0
|
||||
|
||||
const links = [
|
||||
{ to: '/', label: '时间线', icon: PhHouse },
|
||||
@@ -42,7 +46,17 @@ function isOn(l) {
|
||||
}
|
||||
|
||||
function onScroll() {
|
||||
scrolled.value = (window.scrollY || 0) > 8
|
||||
const y = window.scrollY || 0
|
||||
scrolled.value = y > 8
|
||||
// 页首附近不藏(没什么可让的路),滚过一屏的 1/8 才启用;
|
||||
// 方向反转立即回来,误差抖动(|Δ|<2px)不触发
|
||||
if (menuOpen.value) {
|
||||
barHidden.value = false
|
||||
} else if (Math.abs(y - lastY) >= 2) {
|
||||
if (y > lastY && y > 80) barHidden.value = true
|
||||
else barHidden.value = false
|
||||
}
|
||||
lastY = y
|
||||
}
|
||||
|
||||
function toggleMenu() {
|
||||
@@ -119,8 +133,9 @@ function toggleTheme() {
|
||||
</header>
|
||||
|
||||
<!-- 窄屏:顶部玻璃条(品牌 + 汉堡)。桌面 display:none。
|
||||
必须待在 .top 外面:.top 有 backdrop-filter,会给 fixed 后代当包含块。 -->
|
||||
<header class="top-m">
|
||||
必须待在 .top 外面:.top 有 backdrop-filter,会给 fixed 后代当包含块。
|
||||
向下滑动自动藏起(.bar-hide),给内容让路;向上一滑立刻回来。 -->
|
||||
<header class="top-m" :class="{ 'bar-hide': barHidden }">
|
||||
<RouterLink class="top-m-brand" to="/">
|
||||
<span class="av"><AuthorAvatar /></span>
|
||||
<span>{{ title() }}</span>
|
||||
|
||||
@@ -61,7 +61,11 @@ html[data-ui='vivid'] .top-m {position:fixed;z-index:120;
|
||||
border-bottom:1px solid var(--line);
|
||||
background:color-mix(in srgb,var(--card) 82%,transparent);
|
||||
backdrop-filter:blur(20px) saturate(1.5);
|
||||
-webkit-backdrop-filter:blur(20px) saturate(1.5);}
|
||||
-webkit-backdrop-filter:blur(20px) saturate(1.5);
|
||||
transition:transform .28s var(--ease);}
|
||||
/* 向下滑动自动藏起:transform 滑出屏幕,不占布局本来也不占,纯粹让开视线。
|
||||
抽屉开着时 JS 保证不加这个类(汉堡是 ✕,不能消失) */
|
||||
html[data-ui='vivid'] .top-m.bar-hide {transform:translateY(-105%)}
|
||||
html[data-ui='vivid'] .top-m-brand {display:flex;align-items:center;gap:10px;
|
||||
font-weight:700;font-size:14px;letter-spacing:.02em;color:var(--ink);}
|
||||
html[data-ui='vivid'] .top-m-brand .av {width:28px;height:28px;flex:none;color:var(--ink);}
|
||||
|
||||
Reference in new issue
Block a user