fixed 返回顶部功能
This commit is contained in:
1 parent
39651e163a
commit
f1494d10dd
6 files changed
+93
-8
No files matched your search
@@ -10,12 +10,43 @@ function isMobile() {
|
||||
// 文章图片灯箱
|
||||
window.ViewImage && ViewImage.init('.post-content img');
|
||||
|
||||
// 激活返回顶部插件
|
||||
$(function () {
|
||||
$.scrollUp({
|
||||
animation: 'fade',
|
||||
scrollImg: true
|
||||
});
|
||||
// Pure JavaScript Back to Top (High Performance)
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
var backToTopButton = document.getElementById('back-to-top');
|
||||
if (backToTopButton) {
|
||||
var isVisible = false;
|
||||
var ticking = false;
|
||||
|
||||
function update() {
|
||||
if (window.scrollY > 300) {
|
||||
if (!isVisible) {
|
||||
backToTopButton.classList.add('show');
|
||||
isVisible = true;
|
||||
}
|
||||
} else {
|
||||
if (isVisible) {
|
||||
backToTopButton.classList.remove('show');
|
||||
isVisible = false;
|
||||
}
|
||||
}
|
||||
ticking = false;
|
||||
}
|
||||
|
||||
window.addEventListener('scroll', function() {
|
||||
if (!ticking) {
|
||||
window.requestAnimationFrame(update);
|
||||
ticking = true;
|
||||
}
|
||||
}, { passive: true });
|
||||
|
||||
backToTopButton.addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
window.scrollTo({
|
||||
top: 0,
|
||||
behavior: 'smooth'
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// loader定时器
|
||||
|
||||
Reference in new issue
Block a user