黑白球交替动画

又一个不太理解的动画效果,就当练习了

<template>
    <div class="mainrouter"
        style="background-color: rgb(117, 115, 241);display: flex;justify-content: center;align-items: center;">
        <div class="yvan">
            <div class="yvan-nei" v-for="(item,index) in 36" :key="index"></div>
        </div>
    </div>
</template>
<style lang="scss">
$x: 300px;
$y: 300px;
$x2: 20px;
$y2: 20px;
// 小球的数量
$num: 36;
// 小球旋转角度
$PDeg: 360deg/$num;
// 运动时间
$duration: 2s;

.yvan {
    width: $x;
    height: $y;
    border-radius: 50%;
    // border: 1px solid white;
    position: relative;


    .yvan-nei {
        width: $x2;
        height: $y2;
        // background: red;
        position: absolute;
        left: $x/2-$x2/2px;

        // 设置旋转半径
        transform-origin: center $x/2 + $x2/2;
        top: (-$y2/2);
        // 设置
        // 设置井深
        perspective: 80px;
        // 
        transform-style: preserve-3d;

        @for $i from 1 through $num {
            &:nth-child(#{$i}) {
                transform: rotate(($i+1)*$PDeg);

                // 设置动画延迟时间
                &::before,
                &::after {
                    animation-delay: -$duration / $num *($i - 1) *6;
                }

            }
        }

        &::before,
        &::after {
            content: '';
            display: block;
            width: inherit;
            height: inherit;
            border-radius: 50%;
            position: absolute;
        }

        &::before {
            background: black;
            top: -100%;
            animation: router-black $duration infinite; //linear匀速 infinite无限重复

            // 黑球运动动画,只看一个黑球的移动轨迹,发现是在3d上进行
            // 先沿着x轴正方向移动100%,然后沿着y轴正方向移动200%,最后回到原点
            @keyframes router-black {
                0% {
                    // 运动时间曲线
                    animation-timing-function: ease-in;
                }

                25% {
                    transform: translate3d(0, 100%, $x2);
                    animation-timing-function: ease-out;
                }

                50% {
                    transform: translate3d(0, 200%, 0);
                    animation-timing-function: ease-in;
                }

                75% {
                    transform: translate3d(0, 100%, -$x2);
                    animation-timing-function: ease-out;
                }
            }
        }

        &::after {
            background: white;
            top: 100%;
            animation: router-white $duration linear infinite;

            // 白球运动动画,只看一个黑球的移动轨迹,发现是在3d上进行
            @keyframes router-white {
                0% {
                    animation-timing-function: ease-in;
                }

                25% {
                    transform: translate3d(0, -100%, -$x2);
                    animation-timing-function: ease-out;
                }

                50% {
                    transform: translate3d(0, -200%, 0);
                    animation-timing-function: ease-in;
                }

                75% {
                    transform: translate3d(0, -100%, $x2);
                    animation-timing-function: ease-out;
                }
            }

        }
    }

}
</style>

  • 10
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值