fix go back top button

This commit is contained in:
邱博亞 2023-12-17 17:00:02 +08:00
parent e56851d1b2
commit 4f030bece9
1 changed files with 8 additions and 12 deletions

View File

@ -328,7 +328,8 @@
// 回到頁面最頂端動態產生DOM // 回到頁面最頂端動態產生DOM
// txt = 按鈕的文字, speed = 捲動時的速度 // txt = 按鈕的文字, speed = 捲動時的速度
goBackTop: function(txt, speed) { goBackTop: function(txt, speed) {
var top = document.createElement('div'); var top = document.createElement('a');
top.href = '#gotocenter';
top.className = 'go-back-top no-print'; top.className = 'go-back-top no-print';
top.textContent = txt || 'top'; top.textContent = txt || 'top';
doc.body.appendChild(top); doc.body.appendChild(top);
@ -348,17 +349,12 @@
// 捲動效果 // 捲動效果
$('.go-back-top').on('click', function() { $('.go-back-top .top').on('click', function() {
$('body, html').animate({ setTimeout(function(){
scrollTop: 0 $('body, html').animate({
}, speed || 300); scrollTop: 0
return false; }, speed || 300);
}); }, 10);
$('.top').on('click', function() {
$('body, html').animate({
scrollTop: 0
}, speed || 300);
return false;
}); });
}, },