统计
  • 建站日期:2025-10-20
  • 文章总数:541 篇
  • 评论总数:55 条
  • 分类总数:15 个
  • 最后更新:10月25日
文章 未分类

仿bilibili个人主页返回顶部小火箭

樊鑫
首页 未分类 正文
广告

今天分享一个仿b站的小火箭,基本上所有站都有可以用


仿bilibili个人主页返回顶部小火箭
-樊不烦博客
-第1
张图片

你们可以自己试试效果,感觉还不错,由于技术有限,只能做到悬停动画,还做不到点击动画,b站扒下来的js代码又不能直接用,下面放一下食用代码

[hide type=comment]

<style>
    .to-top {
        position: fixed;
        display: none;
        bottom: 100px;
        right: 20px;
        width: 62px;
        height: 85px;
        cursor: pointer;
        background-image: url(//s1.hdslb.com/bfs/static/jinkela/space/asserts/space-to-top.png);
        background-position: -40px -44px;
        transition: transform 0.3s ease-in;
        transform: translateY(0);
    }
    .to-top:hover {
                animation: up-top .4s steps(1) infinite;
            }
    .to-top.fly {
        transform: translateY(-1000px);
    }
    @keyframes up-top{
        0% {
                    background-position-x: -40px;
        }
        16.5% {
                    background-position-x: -183px;
        }
        33% {
                    background-position-x: -326px;
        }
        49.5% {
                    background-position-x: -469px;
        }
        66% {
                    background-position-x: -612px;
        }
        82.5% {
                    background-position-x: -755px;
        }
        100% {
                    background-position-x: -40px;
        }
    }

    @media (min-width: 1420px) {
        .to-top {
            margin-left: 712px;
        }
    }
</style>
<div class="to-top"></div>
<script>
    // 检测滚动位置来控制按钮显示/隐藏
    function toggleToTopVisibility() {
        if ($(window).scrollTop() > 0) {
            $(".to-top").fadeIn(100);
        } else {
            $(".to-top").fadeOut(100);
        }
    }
    // 检查滚动位置来设置初始按钮的显示/隐藏状态
    toggleToTopVisibility();
    // 点击按钮后滚动到顶部
    $(".to-top").click(function() {
        $(this).addClass("fly");
        setTimeout(() => {
            $(this).removeClass("fly");
        }, 300);
        $("html, body").animate({ scrollTop: 0 }, "fast");
    });
    // 监听滚动事件以动态显示/隐藏按钮
    $(window).scroll(toggleToTopVisibility);
</script>

[/hide]

本文转载:若歆馆

本文标签: 网站美化

版权说明
提示:本作品是由 樊不烦博客 用户 投递的作品。
欢迎转载,但请务必注明来源地址:
所有资源为用户上传分享,若发现您的权利被侵害,请联系QQ167471919,我们尽快处理。
文章采用: 《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权。

发表评论

已有 2 条评论

  1. dGNDdByf Lv.1
    3 个月前         Win 10 /     Google Chrome

    说道:看起来不错

  2. 樊雨熙 Lv.2
    4 个月前         Android /     Google Chrome

    说道:满满的干货,收藏了慢慢学!📚

舔狗日记

    love love love