feat(toc): add sticky positioning and entry animation for improved UX

这个提交包含在:
rohow
2026-01-30 23:06:59 +08:00
未验证
父节点 d9a636c54e
当前提交 09b0a6bbde
修改 4 个文件,包含 47 行新增17 行删除
+18 -1
查看文件
@@ -10,6 +10,10 @@
--dash-spacing: 10px; --dash-spacing: 10px;
--dash-width: 2px; --dash-width: 2px;
// 进入动画初始状态(仅 sticky 激活时播放)
opacity: 1;
transition: opacity 0.3s ease-in-out;
// 虚线背景层 - 带遮罩 // 虚线背景层 - 带遮罩
&::before { &::before {
content: ''; content: '';
@@ -81,6 +85,10 @@
opacity: 0.8; opacity: 0.8;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
/* 进入动画:透明度由0到1,宽度由中间到100% */
animation: sticky-in 0.5s ease-in-out forwards;
opacity: 1;
&::before { &::before {
animation: line-flow 1.5s linear infinite; animation: line-flow 1.5s linear infinite;
mask-image: none; mask-image: none;
@@ -126,4 +134,13 @@
left: 80%; left: 80%;
opacity: 0; opacity: 0;
} }
} }
@keyframes sticky-in {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
+24 -13
查看文件
@@ -1,14 +1,21 @@
@import "variables"; @import "variables";
.post-toc-sticky {
position: sticky;
top: 0;
z-index: 100;
width: 0;
height: 0;
overflow: visible;
transform: translate(-260px, 100px);
}
.post-toc { .post-toc {
position: absolute; position: relative;
left: -280px;
top: 85px;
width: 200px; width: 200px;
max-height: calc(100vh - 200px); max-height: calc(100vh - 200px);
overflow-y: auto; overflow-y: auto;
overflow-x: hidden; overflow-x: hidden;
z-index: 100;
font-size: 0.8rem; font-size: 0.8rem;
line-height: 1.6; line-height: 1.6;
color: var(--foreground); color: var(--foreground);
@@ -126,6 +133,18 @@
transition: color 0.15s ease, opacity 0.15s ease; transition: color 0.15s ease, opacity 0.15s ease;
} }
// 左侧激活指示线
&::before {
content: '' !important;
position: absolute;
left: -10px !important;
top: 4px;
bottom: 4px;
width: 2px;
background-color: transparent;
border-radius: 1px;
}
// 活跃状态 // 活跃状态
&--active { &--active {
background-color: color-mix(in srgb, var(--brightBlue) 15%, transparent); background-color: color-mix(in srgb, var(--brightBlue) 15%, transparent);
@@ -139,16 +158,8 @@
color: var(--brightBlue); color: var(--brightBlue);
} }
// 左侧激活指示线
&::before { &::before {
content: '' !important;
position: absolute;
left: -10px !important;
top: 4px;
bottom: 4px;
width: 2px;
background-color: var(--brightBlue); background-color: var(--brightBlue);
border-radius: 1px;
} }
} }
} }
@@ -178,7 +189,7 @@
&__icon { &__icon {
margin-right: 6px; margin-right: 6px;
color: var(--yellow); color: var(--red);
} }
&__title { &__title {
+4 -2
查看文件
@@ -4,8 +4,8 @@
th:replace="~{modules/layout :: html(title = |${post.spec.title} - ${site.title}|, header = null, content = ~{::content}, footer = null)}" th:replace="~{modules/layout :: html(title = |${post.spec.title} - ${site.title}|, header = null, content = ~{::content}, footer = null)}"
> >
<th:block th:fragment="content"> <th:block th:fragment="content">
<div class="post" x-data="postLineNum" x-init="init()"> <!-- 目录组件 -->
<!-- 目录组件 --> <div class="post-toc-sticky">
<div class="post-toc" x-data="postToc" x-init="init()"> <div class="post-toc" x-data="postToc" x-init="init()">
<div class="toc-header"> <div class="toc-header">
<span class="toc-header__icon">&lt;&gt;</span> <span class="toc-header__icon">&lt;&gt;</span>
@@ -25,6 +25,8 @@
</template> </template>
</ul> </ul>
</div> </div>
</div>
<div class="post" x-data="postLineNum" x-init="init()">
<h1 class="post-title" th:text="'< ' + ${post.spec.title} + ' >'">Post Title</h1> <h1 class="post-title" th:text="'< ' + ${post.spec.title} + ' >'">Post Title</h1>
<div class="post-meta"> <div class="post-meta">
<span class="post-date" th:text="${#dates.format(post.spec.publishTime,'yyyy-MM-dd')}"> publishTime </span> <span class="post-date" th:text="${#dates.format(post.spec.publishTime,'yyyy-MM-dd')}"> publishTime </span>
+1 -1
查看文件
@@ -13,5 +13,5 @@ spec:
repo: https://git.dev.cm/theme-terminal repo: https://git.dev.cm/theme-terminal
settingName: "theme-terminal-setting" settingName: "theme-terminal-setting"
configMapName: "theme-terminal-configMap" configMapName: "theme-terminal-configMap"
version: 1.2.2 version: 1.2.3
require: ">=2.22.0" require: ">=2.22.0"