vue步骤条

该代码示例展示了如何使用Vue.js创建一个带有动态状态的步骤条组件。通过ref和reactive管理当前活动步骤,nextStep和lastStep方法处理步骤的前进和后退操作。样式设计包括不同步骤的圆圈和指向箭头效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在这里插入图片描述

<template>
  <div class="test">
    <div class="stepBox">
      <div class="item">
        <div class="stepItem" :class="{ item5: index == 4, active: item.stepIndex <= activeIndex }"
          v-for="(item, index) in listData.list" :key="index">
          <div class="cont">{{ item.title }}</div>
          <div class="triangle"
            :class="{ triangle_2: index >= 4, triangle_3: index >= 5, triangle_4: index == 5, triangle_5: index == 3, triangle_6: index == 4, activeTriangle: item.stepIndex <= activeIndex }">
          </div>
        </div>
      </div>
    </div>
    <div class="bu">
      <button @click="lastStep">上一步</button>
      <button class="step" @click="nextStep">下一步</button>
    </div>
</div>
</template>

<script setup>


import { ref, reactive } from 'vue'
const activeIndex = ref(1) //判断进行到哪一步
const listData = reactive({
  list: [
    {
      stepIndex: 1,
      title: '项目1'
    },
    {
      stepIndex: 2,
      title: '项目2'
    },
    {
      stepIndex: 3,
      title: '项目3'
    },
    {
      stepIndex: 4,
      title: '项目4'
    },

    {
      stepIndex: 5,
      title: '项目5'
    },
    {
      stepIndex: 9,
      title: '项目9'
    },
    {
      stepIndex: 8,
      title: '项目8'
    },
    {
      stepIndex: 7,
      title: '项目7'
    },
    {
      stepIndex: 6,
      title: '项目6'
    }
  ]
})
const nextStep = () => {
  activeIndex.value += 1;
}
const lastStep = () => {
  activeIndex.value -= 1;
}

</script>

<style lang="scss" scoped>
.test {
  padding-top: 100px;
  padding-left: 100px;
}

.bu {
  margin-top: 50px;

  .step {
    margin-left: 40px;
  }
}

.stepBox {
  width: 800px;
  height: 300px;
  border-radius: 0px 150px 150px 0px;
  border: 2px dotted #DDDDDD;
  border-left: 0;
  position: relative;

  .item {
    position: absolute;
    display: flex;
    align-content: space-between;
    top: -40px;
    width: 90%;
    flex-wrap: wrap;
    height: 380px;

  }
}

.stepItem {
  width: 80px;
  height: 80px;
  background: #DDDDDD;
  border-radius: 50%;
  margin-left: 18%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;

  .triangle {
    position: absolute;
    border-top: 30px solid transparent;
    border-bottom: 30px solid transparent;
    border-left: 30px solid #DDDDDD;
    right: -100%;
    transform: translateY(-50%);
    top: 50%;

  }
// 下方小三角的朝向
  .triangle_2 {
    rotate: 180deg;
    top: -20px;

  }

  .triangle_3 {
    left: -100%;
    right: auto;
  }

  // 消除最后一个小三角
  .triangle_4 {
    display: none;
  }

  .triangle_5 {
    top: 81px;
    right: -45px;
    rotate: 48deg;

  }

  .triangle_6 {
    top: 89px;
    right: 81px;
    rotate: 131deg;
  }

  .activeTriangle {
    border-top: 30px solid transparent;
    border-bottom: 30px solid transparent;
    border-left: 30px solid skyblue;
  }

}

.stepItem:nth-child(5n+1) {
  margin-left: 0;
}

.item5 {
  position: absolute;
  right: calc(-10% - 40px);
  transform: translateY(-50%);
  top: 50%;
}

.active {
  background: skyblue;
}
</style>
实现Vue步骤线条动画效果,可以通过使用CSS动画以及Vue 3的过渡效果来实现。首先,使用CSS动画来控制线段的运动效果。可以通过设置关键帧和过渡效果,例如@keyframes和transition属性,来控制线段的位置和样式的变化。这样可以实现线条的平滑移动和渐变效果。 接下来,可以结合Vue 3的过渡效果来实现平滑的动画过渡效果。Vue 3提供了过渡组件和过渡类名,可以在组件进入和离开时添加类名,从而触发过渡效果。可以使用Vue 3的<transition>组件来包裹线段元素,并设置进入和离开时的过渡类名,从而实现线段的动态变化效果。 要实现带箭头的线段运动动画,可以使用Vue 3中提供的canvas和requestAnimationFrame来实现。具体步骤如下: 1.Vue组件中,创建一个canvas元素,并设置其宽度和高度。 2. 在canvas中绘制线段,并设置线段的起点和终点。 3. 使用requestAnimationFrame方法创建一个循环,在每一帧中更新线段的位置和样式。 4. 根据需要,可以添加箭头效果,例如在线段末端绘制一个三角形箭头。 通过以上步骤,就可以实现Vue步骤线条动画效果。可以根据具体的需求和设计来设置线段的样式、动画效果以及箭头效果。同时,可以参考Vue 3的过渡和动画指南以获取更多关于过渡效果的使用方法和技巧。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值