js实现顺时针加载点动画

效果图如下

用了比较笨的方法settimeout,实现的

1、有一个dom,用背景图片

2、分别定义了五个点测试

3、js定义了一个函数用来每个一秒增加一个点显示

4、显示完成之后,隐藏所有的点

timeDo() {
            for (let i = 1; i <= 5; i++) {
                setTimeout(() => {
                    let dom = document.querySelector(`#dot${i}`)
                    dom.style.display = 'block'
                }, 1000 * i);
            }
            setTimeout(() => {
                for (let i = 1; i <= 5; i++) {
                    let dom = document.querySelector(`#dot${i}`)
                    dom.style.display = 'none'
                }
            }, 6000);
        }

5、定义一个计时器,重复显示

this.interval = setInterval(() => {
                console.log(123);
                this.timeDo()
            }, 6000)

完整代码

<template>
    <div class="container">
        <!-- 24个 -->
        <span id="dot1" style="display: none;"></span>
        <span id="dot2" style="display: none;"></span>
        <span id="dot3" style="display: none;"></span>
        <span id="dot4" style="display: none;"></span>
        <span id="dot5" style="display: none;"></span>
    </div>
</template>
<script>
export default {
    data() {
        return {
            interval: null
        }
    },
    mounted() {
        this.init()
    },
    methods: {
        init() {
            this.timeDo()
            this.interval = setInterval(() => {
                console.log(123);
                this.timeDo()
            }, 6000)
        },
        timeDo() {
            for (let i = 1; i <= 5; i++) {
                setTimeout(() => {
                    let dom = document.querySelector(`#dot${i}`)
                    dom.style.display = 'block'
                }, 1000 * i);
            }
            setTimeout(() => {
                for (let i = 1; i <= 5; i++) {
                    let dom = document.querySelector(`#dot${i}`)
                    dom.style.display = 'none'
                }
            }, 6000);
        }
    },
    destroyed() {
        if(this.interval) {
            clearInterval(this.interval)
        }
        this.interval = null
    }
}
</script>
<style lang="less" scoped>
.container {
    width: 532px;
    height: 532px;
    background: url('@/assets/circle_1.png') no-repeat center;
    position: relative;

    #dot1 {
        width: 28px;
        height: 38px;
        position: absolute;
        left: 250px;
        top: 410px;
        background-color: #15DBFF;
        border-radius: 5px;
    }

    #dot2 {
        width: 28px;
        height: 38px;
        position: absolute;
        left: 207px;
        top: 404px;
        background-color: #15DBFF;
        border-radius: 5px;
        transform: rotate(14deg);
    }

    #dot3 {
        width: 28px;
        height: 38px;
        position: absolute;
        left: 168px;
        top: 387px;
        background-color: #15DBFF;
        border-radius: 5px;
        transform: rotate(30deg);
    }

    #dot4 {
        width: 28px;
        height: 38px;
        position: absolute;
        left: 136px;
        top: 362px;
        background-color: #15DBFF;
        border-radius: 5px;
        transform: rotate(45deg);
    }

    #dot5 {
        width: 28px;
        height: 38px;
        position: absolute;
        left: 110px;
        top: 328px;
        background-color: #15DBFF;
        border-radius: 5px;
        transform: rotate(60deg);
    }
}
</style>

图片资源地址:circle_1.png · NevermoreSF/resources - 码云 - 开源中国 (gitee.com)

xdm有更好的实现方法,请指导下

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

chenshuai5

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

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

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

打赏作者

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

抵扣说明:

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

余额充值