若隐若现的芯片

30 篇文章 1 订阅

先看效果:
在这里插入图片描述
再看代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>若隐若现的芯片</title>
    <script src="https://unpkg.co/gsap@3/dist/gsap.min.js"></script>
    <style>
        body {
            background-color: #000000;
            overflow: hidden;
            text-align:center;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        body,
        html {
            height: 100%;
            width: 100%;
            margin: 0;
            padding: 0;
        }

        svg {
            width: 100%;
            height: 100%;
            visibility: hidden;

        }

        .ell, #ai {
            fill: none;
        }
    </style>
</head>
<body>
<svg id="mainSVG" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 800 600">
    <defs>

        <linearGradient id="aiGrad" x1="513.98" y1="290" x2="479.72" y2="320" gradientUnits="userSpaceOnUse">
            <stop offset="0" stop-color="#000" stop-opacity="0" />
            <stop offset=".15" stop-color="#EF476F" />
            <stop offset=".4" stop-color="#359eee" />
            <stop offset=".6" stop-color="#03cea4" />
            <stop offset=".78" stop-color="#FFC43D" />
            <stop offset="1" stop-color="#000" stop-opacity="0" />
        </linearGradient>

    </defs>

    <ellipse class="ell" cx="400" cy="300" rx="80" ry="80" />
    <ellipse class="ell" cx="400" cy="300" rx="80" ry="80" />
    <ellipse class="ell" cx="400" cy="300" rx="80" ry="80" />
    <ellipse class="ell" cx="400" cy="300" rx="80" ry="80" />
    <ellipse class="ell" cx="400" cy="300" rx="80" ry="80" />
    <ellipse class="ell" cx="400" cy="300" rx="80" ry="80" />
    <ellipse class="ell" cx="400" cy="300" rx="80" ry="80" />
    <ellipse class="ell" cx="400" cy="300" rx="80" ry="80" />
    <ellipse class="ell" cx="400" cy="300" rx="80" ry="80" />
    <ellipse class="ell" cx="400" cy="300" rx="80" ry="80" />
    <ellipse class="ell" cx="400" cy="300" rx="80" ry="80" />
    <ellipse class="ell" cx="400" cy="300" rx="80" ry="80" />
    <ellipse class="ell" cx="400" cy="300" rx="80" ry="80" />
    <ellipse class="ell" cx="400" cy="300" rx="80" ry="80" />
    <ellipse class="ell" cx="400" cy="300" rx="80" ry="80" />
    <ellipse class="ell" cx="400" cy="300" rx="80" ry="80" />
    <ellipse class="ell" cx="400" cy="300" rx="80" ry="80" />
    <ellipse class="ell" cx="400" cy="300" rx="80" ry="80" />
    <ellipse class="ell" cx="400" cy="300" rx="80" ry="80" />
    <ellipse class="ell" cx="400" cy="300" rx="80" ry="80" />
    <ellipse class="ell" cx="400" cy="300" rx="80" ry="80" />
    <ellipse class="ell" cx="400" cy="300" rx="80" ry="80" />
    <ellipse class="ell" cx="400" cy="300" rx="80" ry="80" />
    <ellipse class="ell" cx="400" cy="300" rx="80" ry="80" />
    <ellipse class="ell" cx="400" cy="300" rx="80" ry="80" />
    <ellipse class="ell" cx="400" cy="300" rx="80" ry="80" />
    <ellipse class="ell" cx="400" cy="300" rx="80" ry="80" />
    <ellipse class="ell" cx="400" cy="300" rx="80" ry="80" />
    <ellipse class="ell" cx="400" cy="300" rx="80" ry="80" />
    <ellipse class="ell" cx="400" cy="300" rx="80" ry="80" />
    <path id="ai" opacity=0.85 d="m417.17,323.85h-34.34c-3.69,0-6.67-2.99-6.67-6.67v-34.34c0-3.69,2.99-6.67,6.67-6.67h34.34c3.69,0,6.67,2.99,6.67,6.67v34.34c0,3.69-2.99,6.67-6.67,6.67Zm-5.25-12.92v-21.85c0-.55-.45-1-1-1h-21.85c-.55,0-1,.45-1,1v21.85c0,.55.45,1,1,1h21.85c.55,0,1-.45,1-1Zm23.08-16.29h-11.15m-47.69,0h-11.15m70,10.73h-11.15m-47.69,0h-11.15m40.37,29.63v-11.15m0-47.69v-11.15m-10.73,70v-11.15m0-47.69v-11.15" stroke="url(#aiGrad)" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" />
</svg>
</body>
<script>
    gsap.config({trialWarn: false});
    let select = s => document.querySelector(s),
        toArray = s => gsap.utils.toArray(s),
        mainSVG = select('#mainSVG'),
        allEll = toArray('.ell'),
        colorArr = ['#359EEE', '#FFC43D','#EF476F','#03CEA4']

    let colorInterp = gsap.utils.interpolate(colorArr);

    gsap.set(mainSVG, {
        visibility: 'visible'
    })

    function animate (el, count) {
        let tl = gsap.timeline({
            defaults: {
                ease: 'sine.inOut'
            },
            repeat: -1
        });
        gsap.set(el, {
            opacity:1- count/(allEll.length),
            stroke: colorInterp(count/(allEll.length))
        })

        tl.to(el, {
            attr: {
                ry: `-=${count*2.3}`,
                rx: `+=${count*1.4}`
            },
            ease: 'sine.in'
        })
            .to(el, {
                attr: {
                    ry: `+=${count*2.3}`,
                    rx: `-=${count*1.4}`
                },
                ease: 'sine'
            })
            .to(el, {
                duration: 1,
                rotation: -180,
                transformOrigin: '50% 50%'
            }, 0).timeScale(0.5)
    }
    allEll.forEach((c, i) => {
        gsap.delayedCall(i/(allEll.length-1), animate, [c, i+1])
    })
    gsap.to('#aiGrad', {
        duration: 4,
        delay: 0.75,
        attr: {
            x1: '-=300',
            x2: '-=300'
        },
        scale: 1.2,
        transformOrigin: '50% 50%',
        repeat: -1,
        ease: 'none'
    })
    gsap.to('#ai', {
        duration: 1,
        scale: 1.1,
        transformOrigin: '50% 50%',
        repeat: -1,
        yoyo: true,
        ease: 'sine.inOut'
    })

</script>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

timi先生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值