漏刻有时数据可视化Echarts组件开发(1):报警状态组件CSS代码及封装函数

这篇博客展示了如何使用CSS和JavaScript实现状态指示器的样式设计,包括不同状态的颜色表示和动态变化。通过`.stuNum`类设置不同状态的背景颜色,以及`.temp`类实现状态按钮的动画效果。示例中包含正常、过高和过低三种状态,并通过`getBgColor`函数根据随机生成的数值改变状态按钮的背景和对应文字说明。
摘要由CSDN通过智能技术生成

在这里插入图片描述

组状态显示

 .stuNum1 {
            display: inline-block;
            border-radius: 50%;
            background: #7CB854;
            margin: auto 5px;
            width: 1rem;
            height: 1rem;
            vertical-align: middle;
        }

        .stuNum2 {
            display: inline-block;
            border-radius: 50%;
            background: #DB2F2C;
            margin: auto 5px;
            width: 15px;
            height: 15px;
            vertical-align: middle;
        }

        .stuNum3 {
            display: inline-block;
            border-radius: 50%;
            background: #3EC6F0;
            margin: auto 5px;
            width: 15px;
            height: 15px;
            vertical-align: middle;
        }
<div class="status">
    <span id="cur">状态说明</span>
    <span class="stuNum1"></span><span id="normal">正常</span>
    <span class="stuNum2"></span><span id="heightNorm">过高</span>
    <span class="stuNum3"></span><span id="lowNorm">过低</span>
</div>

单个状态动画

        /*状态按钮*/
        .temp {
            display: inline-block;
            border-radius: 50%;
            width: 15px;
            height: 15px;
            line-height: 15px;
            color: rgba(255, 255, 255, 0.5);
            text-align: center;
            margin: auto 5px;
        }

        /*过高*/
        .tempbg1 {
            background: #DB2F2C;
        }

        /*正常*/
        .tempbg2 {
            background: #438a7a;
        }

        /*过低*/
        .tempbg3 {
            background: #3EC6F0;
        }
<div class="status">
    <span class="temp" id="alert"></span><span id="normal">正常</span>
</div>
    var timerAll;
    getBgColor("#alert", "#normal", 3);
    clearInterval(timerAll);
    timerAll = setInterval(function () {
        var temp = randData(-5, 20);
        getBgColor("#alert", "#normal", temp);
    }, 300);


    //获取背景色;
    function getBgColor(id, status, num) {
        var min = '0', max = '15';
        if (num > max) {
            $(id).removeClass("tempbg2").removeClass("tempbg3").addClass("tempbg1");//tempbg1
            $(status).html("过高");
        }

        if (num >= min && num <= max) {
            $(id).removeClass("tempbg1").removeClass("tempbg3").addClass("tempbg2");//tempbg2
            $(status).html("正常");
        }

        if (num < min) {
            $(id).removeClass("tempbg1").removeClass("tempbg2").addClass("tempbg3");//tempbg3
            $(status).html("过低");
        }
    }

    //随机范围整数;
    function randData(Min, Max) {
        var Range = Max - Min;
        var Rand = Math.random();
        var num = Min + Math.round(Rand * Range);
        return num;
    }

Lockdatav Done!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

漏刻有时

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

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

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

打赏作者

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

抵扣说明:

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

余额充值