vue+elementUI el-progress实现可拖拽进度条
vue+elementUIel-progress实现可拖拽进度条
·
效果图
实现代码
<div class="progress" @mousedown="onDragStart">
<el-progress
style="margin-top: 12px; cursor: pointer"
:percentage="ruleForm.b"
></el-progress>
</div>
<script>
export default {
name: "add",
data() {
return {
isDragEnd: false,
};
},
created() {},
mounted() {},
methods: {
onDragStart(event) {
this.isDragEnd = true;
const progressBox = this.$el.querySelector(".progress");
progressBox.addEventListener("mouseup", this.onDragEnd);
progressBox.addEventListener("mousemove", this.onDrag);
},
onDragEnd() {
this.isDragEnd = false;
},
onDrag(event) {
if (this.isDragEnd) {
const progressBox = this.$el.querySelector(".progress");
const rect = progressBox.getBoundingClientRect();
const width = rect.width;
const offsetX = event.clientX - rect.left;
let percentage = Math.round((offsetX / width) * 100);
percentage = Math.max(0, Math.min(percentage, 100));
this.ruleForm.b = percentage;
}
},
},
};
</script>
更多推荐
已为社区贡献5条内容
所有评论(0)