SVG/CSS路径动画

78 篇文章 2 订阅
17 篇文章 0 订阅
<template>
    <div class="title">路径动画</div>
    <div class="icon-box2">
        <div>CSS 路径动画</div>
        <!-- 这个线是用来显示路径的,并没按照这个线进行运动 -->
        <svg width="200" height="200">
            <path d="M10 80 C 40 10, 65 10, 95 80 S 150 150, 180 80" />
        </svg>
        <div class="icon2"></div>
    </div>
    <div class="icon-box2">
        <div>SVG 路径动画</div>
        <svg width="200" height="200">
            <path id="p1-line1" d="M10 80 C 40 10, 65 10, 95 80 S 150 150, 180 80" />
            <image x="-10px" y="-10px" xlink:href="@/assets/start.png" style="width: 20px; height:20px">
                <!-- 设置动画持续时间为2.2,rotate自动调节旋转角度,循环次数为indefinite -->
                <animateMotion dur="2.2s" rotate="auto" repeatCount="indefinite">
                    <!-- 引用外部的path路径作为图片的运动路径 -->
                    <mpath xlink:href="#p1-line1"></mpath>
                </animateMotion>
            </image>
        </svg>
    </div>
    <div style="clear: both;"></div>
    <br><br>
    <div class="title">闪光线沿着曲线运动</div>
    <div class="icon-box2">
        <div>CSS 路径动画</div>
        <!-- 这个线是用来显示路径的,并没按照这个线进行运动 -->
        <svg width="200" height="200">
            <path d="M10 80 C 40 10, 65 10, 95 80 S 150 150, 180 80" />
        </svg>
        <div class="icon3"></div>
        <div class="icon3" style="animation-delay: 10ms;"></div>
        <div class="icon3" style="animation-delay: 40ms; opacity: 0.9; transform: scale(0.9)"></div>
        <div class="icon3" style="animation-delay: 60ms; opacity: 0.8; transform: scale(0.8)"></div>
        <div class="icon3" style="animation-delay: 80ms; opacity: 0.7; transform: scale(0.7)"></div>
        <div class="icon3" style="animation-delay: 100ms; opacity: 0.6; transform: scale(0.6)"></div>
        <div class="icon3" style="animation-delay: 120ms; opacity: 0.5; transform: scale(0.5)"></div>
        <div class="icon3" style="animation-delay: 140ms; opacity: 0.4; transform: scale(0.4)"></div>
        <div class="icon3" style="animation-delay: 160ms; opacity: 0.3; transform: scale(0.3)"></div>
    </div>

</template>
<script setup>

</script>
<style lang="less" scoped>
.title {
    padding: 5px 10px;
    margin-bottom: 10px;
    font-size: 16px;
    border-bottom: 1px solid #999;
}

svg {
    path {
        stroke: orange;
        fill: none;
        stroke-width: 2;
    }
}

.icon-box2 {
    position: relative;
    float: left;

    div {
        position: absolute;
    }

    .icon2 {
        width: 20px;
        height: 20px;
        border-radius: 50%;
        background-color: red;

        /* 开启定位,配合偏移路径 */
        position: absolute;
        top: 0;
        left: 0;
        /* 元素运动路径 */
        offset-path: path("M10 80 C 40 10, 65 10, 95 80 S 150 150, 180 80");
        /* 初始偏移位置百分比  */
        offset-distance: 10%;
        animation: identifier2 2s linear infinite;
       
    }

    .icon3 {
        width: 10px;
        height: 10px;
        border-radius: 50%;
        background-color: red;
        box-shadow: 0 0 10px red;
        /* 开启定位,配合偏移路径 */
        position: absolute;
        top: 0;
        left: 0;
        /* 元素运动路径 */
        offset-path: path("M10 80 C 40 10, 65 10, 95 80 S 150 150, 180 80");
        /* 初始偏移位置百分比  */
        offset-distance: -10%;
        animation: identifier2 1s linear infinite;

    }

    ;


}

@keyframes identifier2 {
    0% {
        offset-distance: 0%;
    }

    100% {
        offset-distance: 100%;
    }
}
</style>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值