Skip to content

Commit c9c2d72

Browse files
committed
更新
1 parent fd1eb70 commit c9c2d72

1 file changed

Lines changed: 53 additions & 12 deletions

File tree

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@
203203
min-height: 600px;
204204
}
205205

206+
/* 修改文档内容动画方向 */
206207
.doc-section {
207208
position: absolute;
208209
top: 0;
@@ -211,8 +212,8 @@
211212
height: 100%;
212213
padding: 30px;
213214
opacity: 0;
214-
transform: translateX(-50px);
215-
transition: all 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
215+
transform: translateX(0);
216+
transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
216217
pointer-events: none;
217218
overflow-y: auto;
218219
}
@@ -223,9 +224,28 @@
223224
pointer-events: all;
224225
}
225226

226-
.doc-section.exit {
227+
/* 下一页进入动画 - 从右侧进入 */
228+
.doc-section.enter-right {
229+
transform: translateX(100%);
230+
opacity: 0;
231+
}
232+
233+
/* 上一页进入动画 - 从左侧进入 */
234+
.doc-section.enter-left {
235+
transform: translateX(-100%);
236+
opacity: 0;
237+
}
238+
239+
/* 下一页退出动画 - 向左侧退出 */
240+
.doc-section.exit-right {
241+
transform: translateX(-100%);
242+
opacity: 0;
243+
}
244+
245+
/* 上一页退出动画 - 向右侧退出 */
246+
.doc-section.exit-left {
247+
transform: translateX(100%);
227248
opacity: 0;
228-
transform: translateX(50px);
229249
}
230250

231251
.doc-section h2 {
@@ -922,24 +942,38 @@ <h3>未完待续</h3>
922942
contentElement.innerHTML += contentData[key].content;
923943
});
924944
}
925-
926-
function showContent(contentId) {
945+
946+
function showContent(contentId, direction = 'next') {
927947
// 获取当前活动的内容
928948
const currentActive = document.querySelector('.doc-section.active');
929949

930950
if (currentActive && currentActive.id !== contentId) {
951+
// 根据方向设置不同的动画类
952+
const exitClass = direction === 'next' ? 'exit-right' : 'exit-left';
953+
const enterClass = direction === 'next' ? 'enter-right' : 'enter-left';
954+
931955
// 添加退出动画类
932-
currentActive.classList.add('exit');
956+
currentActive.classList.add(exitClass);
933957

934958
// 等待退出动画完成
935959
setTimeout(() => {
936-
currentActive.classList.remove('active', 'exit');
960+
currentActive.classList.remove('active', exitClass);
937961

938962
// 显示新内容
939963
const targetSection = document.getElementById(contentId);
940964
if (targetSection) {
965+
// 添加进入动画类
966+
targetSection.classList.add(enterClass);
941967
targetSection.classList.add('active');
942968

969+
// 强制重绘,确保动画生效
970+
targetSection.offsetHeight;
971+
972+
// 移除进入动画类,触发过渡
973+
setTimeout(() => {
974+
targetSection.classList.remove(enterClass);
975+
}, 10);
976+
943977
// 更新页面标题
944978
document.title = `NovaFlare Engine | ${contentData[contentId].title}`;
945979

@@ -958,7 +992,7 @@ <h3>未完待续</h3>
958992
}
959993
}, 100);
960994
}
961-
}, 300); // 与CSS过渡时间匹配
995+
}, 300);
962996
} else if (!currentActive) {
963997
// 首次加载
964998
const targetSection = document.getElementById(contentId);
@@ -1011,17 +1045,24 @@ <h3>未完待续</h3>
10111045
});
10121046
});
10131047

1014-
// 导航按钮点击
10151048
document.addEventListener('click', function(e) {
10161049
if (e.target.closest('.nav-btn.next')) {
10171050
const nextId = e.target.closest('.nav-btn.next').getAttribute('data-next');
1018-
showContent(nextId);
1051+
showContent(nextId, 'next'); // 传递方向参数
10191052
} else if (e.target.closest('.nav-btn.prev')) {
10201053
const prevId = e.target.closest('.nav-btn.prev').getAttribute('data-prev');
1021-
showContent(prevId);
1054+
showContent(prevId, 'prev'); // 传递方向参数
10221055
}
10231056
});
10241057

1058+
// 侧边栏项点击使用默认方向
1059+
sidebarItems.forEach(item => {
1060+
item.addEventListener('click', function(e) {
1061+
e.preventDefault();
1062+
const contentId = this.getAttribute('data-id');
1063+
showContent(contentId, 'next'); // 侧边栏点击使用下一页动画
1064+
});
1065+
});
10251066
// 代码复制功能
10261067
initCodeCopy();
10271068

0 commit comments

Comments
 (0)