MrShi
2025-07-02 573bf54a0056fe6ff2fcd06d31fb10a3c6fec194
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
$(document).ready(function() {
    // 当页面滚动到一定距离时显示返回顶部按钮
    $('#back-to-top').fadeOut();
 
    dingwei()
 
    function dingwei() {
        $('.underline').remove()
        if (window.location.href.indexOf('#section1') !== -1) {
            $('#b').append('<div class="underline"></div>')
            console.log('b')
        } else {
            $('#a').append('<div class="underline"></div>')
            console.log('a')
        }
    }
 
    $(window).scroll(function() {
        if ($(this).scrollTop() > 100) { // 这里可以根据需要调整数值
            $('#back-to-top').fadeIn(); // 显示按钮
        } else {
            $('#back-to-top').fadeOut(); // 隐藏按钮
        }
    });
 
    // 点击按钮时,页面平滑滚动到顶部
    $('#back-to-top').click(function(event) {
        event.preventDefault(); // 阻止链接的默认行为
        $('html, body').animate({scrollTop: 0}, 800); // 页面平滑滚动到顶部,800毫秒完成滚动
    });
});