添加返回顶部按钮

This commit is contained in:
MasonLiu committed 2026-06-02 23:29:42 +08:00
1 parent c4b1f8fd1b
commit 9949072ae0
7 files changed
+233

No files matched your search

+29
View File
@@ -339,5 +339,34 @@ try {
});
})();
</script>
<!-- 返回顶部按钮 -->
<button id="back-to-top" class="back-to-top" title="返回顶部">
↑
</button>
<script>
// 返回顶部功能
(function() {
const backToTopBtn = document.getElementById('back-to-top');
// 滚动时显示/隐藏按钮
window.addEventListener('scroll', function() {
if (window.pageYOffset > 300) {
backToTopBtn.classList.add('show');
} else {
backToTopBtn.classList.remove('show');
}
});
// 点击返回顶部
backToTopBtn.addEventListener('click', function() {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});
})();
</script>
</body>
</html>