用css控制根据动态数据来显示背景图片的高亮进度

 <div class="little-list">
            <div v-for="(item,index) in perseItem" :key="index">
                <div class="little-box">
                    <div class="bg" :style="{'height':(item.score/item.baseScore*100)+'%'}">div>
                    <div class="name">{{item.name}}div>
                div>
                
                <div class="perse-btn" :class="['cur'+(item.st)]" @click="item.st===1&&perseEvent(index+1)" v-html="item.st!==2?`${item.score}成就积分
领奖励`:`已领取`"
>
div> div> div>
<script setup>
import {ref, reactive, onMounted } from 'vue'

const perseItem = ref([
    {
        name: '今日达成1次',
        score: 100,
        baseScore: 1000,
        st: 0
    },{
        name: '今日达成2次',
        score: 1000,
        baseScore: 1000,
        st: 1
    }
])

const perseEvent = ()=> {
    console.log("领取...");
}
.little-list {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    >div {
        margin-bottom: 20px;
        text-align: center;
        .little-box {
            position: relative;
            display: flex;
            align-items: center;
            width: 183px;
            height: 177px;
            color: #e27500;
            font-size: 20px;
            line-height: 1.2;
            &::before {
                position: absolute;
                bottom: 0;
                left: 0;
                content: '';
                width: 183px;
                height: 177px;
                background: url("../../assets/new/little-bg.png") no-repeat bottom;
                background-size: cover;
                filter: grayscale(100%);
                z-index: 1;
            }
            .bg {
                position:absolute;
                width: 100%;
                height: 6%;
                bottom:0;
                left:0;
                z-index:2;
                background: url("../../assets/new/little-bg.png") no-repeat bottom;
                background-size: 183px 177px;
            }
            .name {
                z-index: 3;
                width: 183px;
            }
        }
        .perse-btn {
                position: relative;
                margin-top: -10px;
                padding-top: 10px;
                width: 175px;
                height: 70px;
                line-height: 1.2;
                font-size: 23px;
                color: #ffffff;
                background: #aaaaaa;
                border-radius: 50px;
                z-index: 4;
                &.cur1 {
                    background: #005a92;
                }
                &.cur2 {
                    line-height: 50px;
                }
        }
    }
}

效果图
用css控制根据动态数据来显示背景图片的高亮进度_第1张图片

你可能感兴趣的:(Vue,css,css,前端,vue)