添加返回顶部按钮
This commit is contained in:
1 parent
c4b1f8fd1b
commit
9949072ae0
7 files changed
+233
No files matched your search
@@ -387,5 +387,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>
|
||||
Reference in new issue
Block a user