语言:vue
一、根据计算长度控制样式变化
- 样式如下:
2.代码:根据长度百分比计算样式
<template>
<!-- 步骤条盒子 -->
<div class="steps-box">
<!-- 步骤条 -->
<div
class="Article-steps"
:class="data.stepList.length <= activeIndex ? 'step-over' : ''"
>
<!-- 步骤条背景进度条 -->
<div class="line">
<span
class="plan"
:style="`width:${
(activeIndex - 1) * (100 / (data.stepList.length - 1))
}%`"
></span>
</div>
<!-- 每步部分 -->
<span
class="step"
v-for="(i, index) in data.stepList"
:key="index"
:class="
activeIndex == i.stepIndex || i.stepIndex <= activeIndex
? 'step-active'
: 'step-start'
"
>
<span
class="step-num"
:class="{ active: activeIndex + 1 === i.stepIndex }"
>
<span
class="num"
:class="{ active: activeIndex + 1 === i.stepIndex }"
>{
{
i.stepIndex }}</span
>
</span>
<p class="title" :class="{ active: activeIndex + 1 === i.stepIndex }">
{
{
i.title }}
</p>
</span>
</div>
</div>
</template>
<script>
import {
reactive, ref } from "vue";
export default {
setup() {
const activeIndex = ref(3);
const data = reactive({
//步骤条步数
stepList: [
{
stepIndex: 1,
title: "新录入",
},
{
stepIndex: 2,
title: "带看中",
},
{
stepIndex: 3,
title: "已反馈",
},
{
stepIndex: 4,
title: "意向中",
},
{
stepIndex: 5,
title: "已成交",
},
],
});
return {
data, activeIndex };
},
};
</script>
<style lang="less" scoped>
.steps-box {
user-select: none;
width: 100%;
height: 98px;
position: relative;
background: #f8faff;
// <!-- 步骤条背景进度条 -->
.line {
margin: 0px auto;
position: absolute;
left: 1%;
top: 9px;
background: rgb(204, 204, 204);
width: 97%;
height: 2px;
overflow: hidden;
flex-direction: row;
.plan {
position: absolute;
top: 0;
left: 0;
height: 2px;
transition: 0.5s;
background: #8ab4f3;
}
}
.Article-steps {
display: flex;
justify-content: space-between;
.step {
display: flex;
flex-direction: column;
align-items: center;
.title {
font-size: 17px;
font-weight: bold;
color: #808080;
margin-top: 15px;
&.active {
color: #333 !important;
}
}
.step-num {
width: 20px;
height: 20px;
border-radius: 12px;
display: inline-block;
line-height: 20px;
text-align: center;
border: 2px solid;
color: #808080;
font-weight: bold;
&.active {
color: #333 !important;
transform: rotate(90deg);
background: #f8faff;
}
.num {
display: inline-block;
&.active {
transform: rotate(-90deg);
}
}
}
}
}
//当前所在位置样式
.step-active {
.step-num {
color: #2d7df5 !important;
transform: rotate(90deg);
background: #f8faff;
.num {
transform: rotate(-90deg);
}
}
.title {
color: #2d7df5 !important;
}
}
.step-start {
.step-num {
color: #808080 !important;
transform: rotate(0deg);
background: #f8faff;
}
}
}
</style>
二、模仿element框架的步骤条写法
- 样式如下:
- 代码:
<template>
<div style="background-color: white; padding: 20px">
<div class="steps">
<div class="step" v-for="(i, index) in stepList" :key="index">
<div
class="step-head"
:class="
activevalue == i.stepIndex || i.stepIndex <= activevalue
? 'step-finish'
: 'step-wait'
"
>
<div
class="step-line"
:class="
activevalue == i.stepIndex + 1 || i.stepIndex + 1 <= activevalue
? 'step-finish'
: 'step-wait'
"
>
<i class="step-line-inner"></i>
</div>
<div
class="step-icon"
:class="{ active: activevalue + 1 === i.stepIndex }"
>
<div class="step-icon-text">{
{
i.stepIndex }}</div>
</div>
</div>
<div
class="step-main"
:class="
activevalue == i.stepIndex || i.stepIndex <= activevalue
? 'step-finish'
: 'step-wait'
"
>
<div
class="step-title"
:class="{ active: activevalue + 1 === i.stepIndex }"
>
{
{
i.title }}
</div>
</div>
</div>
</div>
</div>
</template>
<script>
import {
ref } from "vue";
export default {
props: {
activevalue: String, //父组件传过来的数据
},
setup() {
// const activevalue = ref(3);
const stepList = ref();
//步骤条步数
stepList.value = [
{
stepIndex: 1,
title: "新录入",
},
{
stepIndex: 2,
title: "带看中",
},
{
stepIndex: 3,
title: "已反馈",
},
{
stepIndex: 4,
title: "已成交",
},
];
return {
stepList };
},
};
</script>
<style lang="less" scoped>
.steps {
display: flex;
text-align: center;
.step {
flex-basis: 25%;
margin-right: 0px;
.step-head {
position: relative;
width: 100%;
.step-line {
left: 50%;
right: -50%;
height: 0.1px;
top: 11px;
position: absolute;
border: 1px solid;
border-color: inherit;
background-color: #c0c4cc;
.step-line-inner {
transition-delay: 0ms;
border-width: 1px;
width: 100%;
display: block;
border: 1px solid;
border-color: inherit;
transition: 0.15s ease-out;
box-sizing: border-box;
width: 0;
height: 0;
}
}
.step-icon {
position: relative;
z-index: 1;
display: inline-flex;
justify-content: center;
align-items: center;
width: 24px;
height: 24px;
font-size: 14px;
box-sizing: border-box;
background: #fff;
transition: 0.15s ease-out;
border-radius: 50%;
border: 2px solid;
border-color: inherit;
&.active {
color: #333 !important;
}
.step-icon-text {
display: inline-block;
user-select: none;
text-align: center;
font-weight: 700;
line-height: 1;
color: inherit;
}
}
}
.step-main {
.step-title {
font-size: 14px;
line-height: 38px;
font-weight: 700;
text-align: center;
&.active {
color: #333 !important;
}
}
}
}
.step:last-of-type .step-line {
display: none;
}
//当前所在位置样式
.step-finish {
color: #2d7df5;
}
.step-wait {
color: #808080;
}
}
</style>