首页 > 其他分享 >会滑行的小球(可复制源代码)

会滑行的小球(可复制源代码)

时间:2024-09-10 16:24:59浏览次数:3  
标签:body x1 attr 50% 小球 gsap duration 源代码 滑行

效果演示

在这里插入图片描述
源代码

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>会滑行的小球</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.9.1/gsap.min.js"></script>
    <style>
        :root{--clr-0:#CCCCCC;--clr-1:#f5f5f5;--clr-2:#232323}body{font-family:'Montserrat',sans-serif;font-size:1rem;background-color:var(--clr-0)}body.light .cover{background-color:var(--clr-0)}#stick-figure-svg{opacity:0;visibility:hidden}body.light .theme-toggle-button{border-color:white;background-color:var(--clr-0)}body.dark .cover{background-color:var(--clr-2)}body.dark .theme-toggle-button{border-color:#b8b1a7;background-color:var(--clr-2)}body.dark #R-leg,body.dark #L-leg{stroke:white}body.light #R-leg,body.light #L-leg{stroke:#232323}.cover{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);width:75px;height:75px;background-color:black;z-index:-1}.container{display:flex;justify-content:center;align-items:center;height:100vh;flex-direction:column;gap:2rem;position:relative;overflow:hidden}button{padding:2rem;cursor:pointer}.theme-toggle-button{width:15rem;height:5rem;border:4px solid white;border-radius:50px;display:flex;align-items:flex-end;padding:0;background-color:var(--clr-0)}#stick-figure-svg{width:147%;height:147%}.template-footer{position:fixed;bottom:0;right:0;height:2rem;width:15rem;border-radius:5px 0 0 0;background-color:#ffffba;display:flex;justify-content:space-between;align-items:center;padding:0.8rem 1.6rem}
    </style>
</head>

<body>
    <div class="container">
        <div class="cover"></div>
        <button type="submit" class="theme-toggle-button">
            <svg width="100%" id="stick-figure-svg" xmlns="http://www.w3.org/2000/svg"
                xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 150 200">
                <defs>
                    <linearGradient id="linear-gradient" x1="27.6" y1="49.33" x2="125.11" y2="135.42"
                        gradientTransform="matrix(1, 0, 0, 1, 0, 0)" gradientUnits="userSpaceOnUse">
                        <stop offset="0" stop-color="#f0b402" />
                        <stop offset=".26" stop-color="#f1a508" />
                        <stop offset=".69" stop-color="#f39210" />
                        <stop offset=".99" stop-color="#f48c13" />
                    </linearGradient>
                    <mask id="faceClip">
                        <circle id="face-clip" cx="58" cy="142" r="57"></circle>
                    </mask>
                </defs>
                <g id="stick-figure">
                    <g id="R-leg" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"
                        stroke-width="4">
                        <line id="R-thigh" x1="70" y1="168" x2="70" y2="138" />
                        <line id="R-calf" x1="70" y1="168" x2="70" y2="198" />
                        <line id="R-foot" x1="70" y1="198" x2="82" y2="198" />
                    </g>
                    <g id="L-leg" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"
                        stroke-width="4">
                        <line id="L-thigh" x1="46" y1="168" x2="46" y2="138" />
                        <line id="L-calf" x1="46" y1="168" x2="46" y2="198" />
                        <line id="L-foot" x1="46" y1="198" x2="34" y2="198" />
                    </g>
                    <!--       <circle id="face" cx="75" cy="91.18" r="60" fill="url(#linear-gradient)" /> -->
                    <circle id="face" cx="58" cy="132" r="68" fill="url(#linear-gradient)"></circle>
                    <g id="eyes-mouth">
                        <circle id="L-eye" cx="57.68" cy="83.18" r="3.5" />
                        <circle id="R-eye" cx="90.68" cy="83.18" r="3.5" />
                        <path id="mouth"
                            d="M79.53,91.98c.15,0,.25,.22,.22,.45-.27,2-2.29,3.55-4.74,3.55s-4.48-1.55-4.74-3.55c-.03-.23,.07-.45,.22-.45h9.05Z"
                            fill="#fff" transform-origin="center" transform="scale(1.3)" />
                    </g>
                    <g id="highlights" stroke="white" fill="none" stroke-linecap="round" stroke-linejoin="round"
                        stroke-width="2">
                        <path id="hl-1" d="M76.06,145.54l-13.33-13.33" />
                        <path id="hl-2" d="M92.73,132.21l-13.33,13.33" />
                        <path id="hl-3" d="M63.63,161.31l13.33-13.33" />
                        <path id="hl-4" d="M92.73,161.31l-13.33-13.33" />
                    </g>
                </g>
            </svg>
        </button>

    </div>
</body>
<script>
    gsap.set("#stick-figure-svg", { autoAlpha: 1 });
    gsap.set("#stick-figure", { x: -135 });
    gsap.set("#eyes-mouth", { transformOrigin: "50% 50%" })
    gsap.set("#L-foot", { attr: { x1: 46, x2: 58 } });
    gsap.set("#highlights", { autoAlpha: 0 })
    gsap.set(["#R-foot", "#L-foot", "#R-thigh", "#R-calf", "#L-thigh", "#L-calf"], { autoAlpha: 0 })
    gsap.set(".cover", { xPercent: -50, yPercent: -50 })

    let readyForDrag = gsap.timeline({ defaults: { ease: "power1.in", duration: 0.2 } });
    readyForDrag
        .to(
            "#eyes-mouth",
            { x: "+=20" },
            "<"
        )
        .to(["#R-calf"], { attr: { x2: 95, y2: 198 } })
        .to(["#R-foot"], { attr: { x2: 95, x1: 107 } }, "<")
        .to(["#R-foot"], { attr: { y2: 198, y1: 190 } })
        .to(["#L-calf"], { attr: { x2: 71, y2: 198 } })
        .to(["#L-foot"], { attr: { x1: 74, x2: 86 } }, "<")
        .to(["#L-foot"], { attr: { y2: 190 } })

    let highlight_tl = gsap.timeline({ paused: true, defaults: { ease: "power4.in", duration: 0.2 } })
    highlight_tl
        .to("#highlights", { autoAlpha: 1, duration: 0.1 })
        .to("#hl-1", { drawSVG: "0% 100%" })
        .to(["#hl-2", "#hl-3", "#hl-4"], { drawSVG: "100% 0%" }, "<")
        .to("#hl-1", { drawSVG: "50% 100%", autoAlpha: 0 }, "<")
        .to(["#hl-2", "#hl-3", "#hl-4"], { drawSVG: "50% 0%", autoAlpha: 0 }, "<")

    let wakeup_tl = gsap.timeline({ paused: true, defaults: { ease: "power1.in", duration: 0.4 } });

    wakeup_tl
        .to(["#R-foot", "#L-foot", "#R-thigh", "#R-calf", "#L-thigh", "#L-calf"], { autoAlpha: 1, duration: 0.1 })
        .to("#face", { attr: { cy: 90 }, duration: 0.2 })
        .fromTo(
            ["#R-thigh", "#R-calf"],
            { attr: { x1: 85, y1: 198 } },
            { attr: { x1: 85, y1: 173 }, duration: 0.2 },
            "<"
        )
        .fromTo(
            ["#L-thigh", "#L-calf"],
            { attr: { x1: 61, y1: 198 } },
            { attr: { x1: 61, y1: 173 }, duration: 0.2 },
            "<"
        )

        .from(
            "#eyes-mouth",
            { x: 25, y: 40, autoAlpha: 0 },
            "<"
        )
        .from(["#L-eye", "#R-eye"], {
            transformOrigin: "50% 50%",
            scaleY: 0,
        })
        .fromTo(["#L-eye", "#R-eye"], { scaleY: 0 }, { scaleY: 1, duration: 0.1, transformOrigin: "50% 50%" })
        .add(readyForDrag.play())
        .to("#stick-figure", { x: 142.5, duration: 0.8 })
        .to(["#R-foot", "#L-foot"], { attr: { y1: 198, y2: 198 }, duration: 0.1 })
        .to(["#L-foot"], { attr: { x1: 71, x2: 59 }, duration: 0.2 }, "<")
        .to(["#L-calf", "#L-thigh"], { attr: { x1: 71, x2: 71 }, duration: 0.1 }, "<")
        .to(["#R-calf", "#R-thigh"], { attr: { x1: 95, x2: 95 }, duration: 0.1 }, "<")
        .to("#face", { attr: { cx: 83, cy: 75 }, ease: "back" }, "<")
        .to("#eyes-mouth", { x: "-=9", y: "-=5" }, "<")
        .addLabel("goingtosleep")
        .to(["#L-calf", "#L-thigh"], { attr: { x1: 61, x2: 71 } })
        .to(["#R-calf", "#R-thigh"], { attr: { x1: 105, x2: 95 } }, "<")
        .to("#eyes-mouth", { y: "+=60", transformOrigin: "50% 50%", autoAlpha: 0 })
        .to("#face", { attr: { cx: 83, cy: 132 } }, "-=0.2");
    wakeup_tl.timeScale(1.5)
    let playButton = document.querySelector(".theme-toggle-button");
    let themeDark = false
    let cover = document.querySelector(".cover");
    function turnOnDarkModeHandler() {
        document.body.classList.add("dark");
        document.body.classList.remove("light");
        gsap.to(".cover", { width: "100vw", height: "100vh", duration: 1 }).then(() => document.body.style.backgroundColor = "#232323")

    }
    function turnOnLightModeHandler() {
        document.body.classList.add("light");
        document.body.classList.remove("dark");
        gsap.to(".cover", { width: "100vw", height: "100vh", duration: 1 }).then(() => document.body.style.backgroundColor = "#CCCCCC")

    }
    playButton.addEventListener("click", () => {
        gsap.set(".cover", { width: "75px", height: "75px" })
        themeDark = !themeDark
        if (themeDark) {
            wakeup_tl.play().eventCallback("onComplete", turnOnDarkModeHandler)
            highlight_tl.play()
        } else {
            wakeup_tl.reverse().then(turnOnLightModeHandler)
            highlight_tl.restart()
        }
    });
</script>
</html>

标签:body,x1,attr,50%,小球,gsap,duration,源代码,滑行
From: https://blog.csdn.net/lcy1619260/article/details/142094781

相关文章

  • 太极(可复制源代码)
    效果演示HTML<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width,initial-scale=1.0"><title>太极</title&g......
  • 源代码加密是什么?如何做源代码加密?
    源代码加密是什么?如何做源代码加密?在软件开发过程中,版本管理工具如SVN和GIT是不可或缺的组成部分,它们帮助团队管理源代码的变更和版本。然而,这些工具也面临着源代码泄露的安全风险。如果不针对数据进行加密保护,很容易出现“一锅端”的现象。所以源代码开发环境复杂,涉及的开发......
  • SWAP作物生长模型安装教程、数据制备、敏感性分析、气候变化影响、R模型敏感性分析与
    查看原文>>>全流程SWAP农业模型数据制备、敏感性分析及气候变化影响实践技术应用SWAP模型是由荷兰瓦赫宁根大学开发的先进农作物模型,它综合考虑了土壤-水分-大气以及植被间的相互作用;是一种描述作物生长过程的一种机理性作物生长模型。它不但运用Richard方程,使其能够精确的模......
  • PHP毕业设计作品:基于PHP音乐网站音乐平台系统设计与实现开题报告和源代码成品
     博主介绍:黄菊华老师《Vue.js入门与商城开发实战》《微信小程序商城开发》图书作者,CSDN博客专家,在线教育专家,CSDN钻石讲师;专注大学生毕业设计教育和辅导。所有项目都配有从入门到精通的基础知识视频课程,学习后应对毕业设计答辩。项目配有对应开发文档、开题报告、任务书、P......
  • linux安装python3(源代码安装)
    相关软件安装python3安装源代码安装下载python3源码包比如说python3.9.10:https://www.python.org/ftp/python/3.9.10/Python-3.9.10.tar.xz#通过wget下载wgethttps://www.python.org/ftp/python/3.9.10/Python-3.9.10.tar.xz#进行源代码包的解压(xz使用J解压,gz使用......
  • 使用 `Roslyn` 分析器和修复器对.cs源代码添加头部注释
    之前写过两篇关于Roslyn源生成器生成源代码的用例,今天使用Roslyn的代码修复器CodeFixProvider实现一个cs文件头部注释的功能,代码修复器会同时涉及到CodeFixProvider和DiagnosticAnalyzer,实现FileHeaderAnalyzer首先我们知道修复器的先决条件是分析器,比如这里,如果要对代码......
  • 最新微信商城小程序源码搭建指南(附源代码)
     一、前期准备 1.1了解微信商城小程序 微信商城小程序是在微信平台上运行的商城系统,主要形式分为展示型和下单+展示型。展示型主要用于商品信息的展示,不支持在线下单;而下单+展示型则支持在线下单、购物车、订单管理等完整电商功能。 1.2注册与认证 源码及演示:xcxym......
  • 如何用大语言模型分析开源代码?
    要使用大语言模型(如GPT)分析开源代码,比如HyperScan正则开源代码,可以按照以下步骤进行:1.获取代码库首先,需要从开源平台(如GitHub)下载HyperScan的代码库。你可以使用Git命令克隆代码库:gitclonehttps://github.com/intel/hyperscan.git2.分块处理代码由于大语言模型在一次请求中只能......
  • 盘点国内外最好用的12款源代码加密软件:总有一款适合你
    在当今数字化信息飞速发展的时代,源代码的安全性已成为企业和开发者的首要任务之一。源代码不仅是软件的核心,更是企业的知识产权和核心竞争力。为了帮助企业和开发者选择最适合的源代码加密软件,本文将盘点国内外12款最好用的源代码加密工具,每款软件都有其独特的优势,适用于不同的......
  • ceph:源代码编译 nfs-ganesha 2.8.4 (V2-stable)
     step1:从github下载nfs-ganesha(标签2.8.4或分支V2-stable)同时下载相应代码库中指定的版本的libntirpc库代码!注意版本一致。注意ntirpc放到src目录中,要改名为libntirpc或直接做个符号链接libntirpc。 step2:根据你自己的要求或希望的功能,安装依赖 step3:cmake生......