JavaScript+Css实现转向灯、动画执行无限次、循环动画、双闪、animationIterationCount、animation、keyframes、infinite


Html

<div id="app">
    <div class="box">
        <div class="lamp-box">
            <span v-if="leftLamp"></span>
            <span v-if="doubleFlash">←→</span>
            <span v-if="rightLamp"></span>
        </div>

        <div class="button-box">
            <el-button type="success" @click="clickButton('leftLamp')">左转</el-button>
            <el-button type="danger" @click="clickButton('doubleFlash')">双闪</el-button>
            <el-button type="success" @click="clickButton('rightLamp')">右转</el-button>
        </div>
    </div>
</div>

JavaScript

new Vue({
    el: "#app",
    data() {
        return {
            leftLamp: false,
            doubleFlash: false,
            rightLamp: false
        }
    },

    methods: {
        clickButton(type) {
        	// 关闭
            if (this[type]) {
                this[type] = false;
                return false;
            }
            
            this.leftLamp = false;
            this.doubleFlash = false;
            this.rightLamp = false;
            this[type] = !this[type];
        }
    }
});

Style

.box {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.lamp-box,
.button-box {
    border: 1px solid #777;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 300px;
    height: 130px;
    margin-top: 20px;
}

.lamp-box>span {
    font-size: 60px;
    font-weight: 600;
    animation-name: myfirst;
    animation-duration: 1s;
    /* 
     * 播放动画的次数
     * infinite 无限次
     */
    animation-iteration-count: infinite;
}

@keyframes myfirst {
    0% {
        color: #ff0000;
    }

    100% {
        color: transparent;
    }
}

微信小程效果演示

2.0.2X

评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值