Progress 进度条

本文详细描述了如何在Vue项目中使用vuedom结构创建带有动态颜色和百分比的el-progress组件,并配以相应的CSS样式,展示了Web开发中的数据绑定和样式控制。

 vue dom结构如下:

<div class="content">
	<div class="content_" v-for="(item, i) in dataList" :key="i">
		<el-progress stroke-linecap="square" :show-text="false"
					 :style="{left: 'calc(50% - '+ (item.width/2 + 30)             +'px)',top:'calc(50% - '+ (item.width/2) +'px)'}"
					 :stroke-width="12" :color="item.color" :width="item.width" type="dashboard"
					 :percentage="item.rate" define-back-color="#2B364F"></el-progress>
		<div class="progress-info" :class="'progress-info_' + i">
			<div class="progress-info-line"></div>
			<div class="progress-info-round" :style="{background: item.color}"></div>
			<div class="progress-info-label">{{ item.name }}:</div>
			<div class="progress-info-value">{{ item.count }}</div>
		</div>
	</div>
	<p>{{workCount}}</p>
</div>
dataList = [
	{
		width: 200,
		color: '#245387',
		name: 'web',
		count: 0,
		rate: 0,
	},
	{
		width: 150,
		color: '#69FAFE',
		name: 'Java',
		count: 0,
		rate: 0,
	},
	{
		width: 100,
		color: '#F15358',
		name: 'C++',
		count: 0,
		rate: 0,
	}
];

 css scss代码如下:


    .content {
        color: #fff;
        width: calc(100% - 40px);
        height: calc(100% - 74px);
        padding: 0 20px 10px;
        position: relative;
        flex: 1;
        &_ {
            position: absolute;
            width: 100%;
            height: 100%;
            left: 0;
            top: 0;

        }

        /deep/ .el-progress {
            transform: rotate3d(1, 0.4, 0, 180deg);
            position: absolute;
            left: 20px;
        }

        .progress-info {
            display: flex;
            align-items: center;
            position: absolute;
            font-size: 12px;
            height: 20px;
            line-height: 20px;
            width: 50%;
            left: calc(50% - 16px);

            &-line {
                flex: 4;
                height: 1px;
                border-bottom: 1px dashed #ffffff;
            }

            &-label {
                flex: 5;
            }

            &-value {
                flex: 1;
            }

            &-round {
                width: 12px;
                height: 12px;
                border-radius: 50%;
                margin: 0 5px;
            }

            &_0 {
                top: calc(50% - 105px);
            }

            &_1 {
                top: calc(50% - 80px);
            }

            &_2 {
                top: calc(50% - 55px);
            }

        }
        p {
            width: 100px;
            height: 50px;
            font-size: 16px;
            position: absolute;
            left: calc(50% - 85px);
            top: calc(50% - 25px);
            color: #fff;
            line-height: 50px;
            font-weight: bold;
            text-align: center;
        }
    }

效果图如下:

### 自定义 Progress 进度条样式 #### 使用 HTML 和 CSS 实现基本的进度条结构 通过组合使用 `<progress>` 元素和自定义的 CSS 类,可以创建具有独特外观的进度条。对于纵向进度条,可以通过调整 CSS 属性来改变其方向。 ```html <progress id="custom-progress" value="70" max="100"></progress> <div class="vertical-progress-container"> <div class="vertical-progress-bar" style="height: 70%;"></div> </div> ``` 为了使进度条垂直显示并应用特定样式: ```css /* 基础样式 */ .vertical-progress-container { width: 20px; height: 200px; background-color: #f3f3f3; border-radius: 5px; position: relative; } .vertical-progress-bar { width: 100%; background-color: #4caf50; border-radius: 5px; bottom: 0; transition: height 0.6s ease-in-out; } ``` 上述代码片段展示了如何构建一个简单的垂直进度条容器及其内部填充部分[^1]。 #### 利用 JavaScript 动态更新进度值 当需要动态设置进度时,JavaScript 可用于修改 `value` 或者直接操作 DOM 中代表进度百分比的部分。 ```javascript function updateProgress(value) { const progressBar = document.querySelector('.vertical-progress-bar'); progressBar.style.height = `${value}%`; } updateProgress(85); // 设置进度为85% ``` 此函数接收一个表示当前完成程度的比例参数,并据此调整视觉上的高度属性[^2]。 #### 添加交互功能 为了让用户体验更加友好,在某些场景下可能还需要支持用户手动调节进度的功能。这通常涉及到监听鼠标事件以及处理触摸屏设备上的手势动作。 ```javascript let isDragging = false; document.addEventListener('mousedown', function (event) { if (!isDragging && event.target.classList.contains('draggable')) { isDragging = true; } }); document.addEventListener('mousemove', function (event) { if (isDragging) { let rect = event.target.closest('.vertical-progress-container').getBoundingClientRect(); let percent = ((rect.bottom - event.clientY) / rect.height * 100).toFixed(2); if (percent >= 0 && percent <= 100) { updateProgress(percent); } } }); document.addEventListener('mouseup', function () { isDragging = false; }); ``` 这段脚本实现了点击并拖拽进度条末端以更改进度的效果。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值