vue变量 控制 标签包含 不同的class,并实现图标闪烁

* 变量控制class类名:

 : class=" 变量? ' 类名1 类名2 ' : ' 类名1 ' "

* 实现图标闪烁

data先定义变量haveErrorData:true

<div class="floatBtn">
    <div :class="haveErrorData?'errorIcon change':'errorIcon'" style="width: 50px;height: 50px;margin-top: 15px"></div>
    <div style="text-align: center">{{haveErrorData?'异常':'无异常'}}</div>
</div>

这里的样式用的scss嵌套写法,普通css写法只需要把嵌套部分拿出来就行了(&符号要转成上一层类名,例如下方的 &:hover 需要转成 .floatBtn:hover )

.floatBtn{
            position: absolute;
            top: 60px;
            right: 300px;
            z-index: 99;
            width: 100px;
            height: 100px;
            display: flex;
            flex-direction: column;
            align-items: center;
            box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
            &:hover{
                cursor: pointer;
            }
            .errorIcon{
                background: url("../../../assets/cbhs/errorGray.png") no-repeat;
                background-size: 100% 100%;
                &.change{
                    animation: scaleout 1s infinite ease-in-out;
                }
                @keyframes scaleout {
                    0% {
                        background: url("../../../assets/cbhs/errorGray.png") no-repeat;
                        background-size: 100% 100%;
                    } 100% {
                          background: url("../../../assets/cbhs/errorRed.png") no-repeat;
                          background-size: 100% 100%;
                      }
                }
            }
}

最终效果:
在这里插入图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值