当前位置: 首页 > article >正文

html+css+js实现step进度条效果

实现效果

代码实现

HTML部分

<div class="box">
    <ul class="step">
      <li class="circle actives ">1</li>
      <li class="circle">2</li>
      <li class="circle">3</li>
      <li class="progress"></li>
    </ul>
    <ul class="text">
      <li class="item shows">步骤一</li>
      <li class="item">步骤二</li>
      <li class="item">步骤三</li>
    </ul>
    <button>下一步</button>
  </div>

CSS部分

<style>
    *{
      padding: 0;
      margin: 0;
      box-sizing: border-box;
    }
    ul{
      list-style: none;
    }
    .box{
      padding: 25px;
      margin: 50px auto;
      width: 870px;
      height: 160px;
      border: 1px solid #c0c4cc;
    }
    .step{
      position: relative;
      display: flex;
      justify-content: space-between;
      height: 25px;
      line-height: 25px;
    }
    .step::before{
      content: '';
      position: absolute;
      top: 50%;
      transform: translateY(-50%);
      width: 100%;
      height: 3px;
      background-color: #c0c4cc;
      z-index: -2;
    }
    .step .circle{
      position: relative;
      width: 25px;
      height: 25px;
      border-radius: 50%;
      border: 2px solid #c0c4cc;
      text-align: center;
      background-color: #fff;
      line-height: 22px;
      color: #c0c4cc;
    }
    .step .circle.actives{
      position: relative;
      color: black;
      border: 2px solid black;
      font-weight: bold;
    }
    .step .circle.circle.active::before{
      content: '';
      position: absolute;
      left: -2px;
      top: -2px;
      width: 100%;
      height: 100%;
      border-radius: 50%;
      border: 2px solid #67c23a;
      text-align: center;
      background-image: url(./03.png);
      background-size: cover;
      line-height: 22px;
      transition:0.5s ease ;
    }
    .step .progress{
      position: absolute;
      top: 50%;
      transform: translateY(-50%);
      width:0%;
      background-color: #67c23a;
      height: 3px;
      z-index: -1;
      transition:0.5s ease;
    }
    .text{
      display: flex;
      justify-content: space-between;
      height: 38px;
      line-height: 38px;
      margin-bottom: 10px;
    }
    .text li{
      color:#c0c4cc ;
      font-weight: bold;
    }
    .text li.shows{
      color: black;
      font-weight: bold;
    }
    .text li.show{
      color: #67c23a;
    }
    button{
      cursor: pointer;
      padding: 8px 15px;
      background-color: #fff;
      color: #c0c4cc;
      border: 1px solid #c0c4cc;
      border-radius: 3px;
    }
    button:hover{
      border: 1px solid rgba(64, 158, 255, 0.1);
      background-color:rgba(64, 158, 255, 0.1);
      color:#409eff ;
    }
    button:disabled{
      background-color: #e0e0e0;
      cursor: not-allowed;
    }
  </style>

JS部分 

<script>
    const btn=document.querySelector('button')
    const circles=document.querySelectorAll('.circle')
    const progress=document.querySelector('.progress')
    const items=document.querySelectorAll('.item')
    let i = -1
    btn.addEventListener('click',function(){
      i++
      if(i>=circles.length) return btn.disabled=true
      if(i<circles.length){
        // 对号变化
        circles[i].classList.add('active')
        // 文字
        items[i].classList.add('show')
        // 进度条
        const actived=document.querySelectorAll('.active')
        progress.style.width=(actived.length-1) / (circles.length-1) * 100 + '%'
      }
      if(i<circles.length-1){
        circles[i+1].classList.add('actives')
        items[i+1].classList.add('shows')
      }
    })
  </script>


http://www.kler.cn/news/328832.html

相关文章:

  • E36.C语言模拟试卷1第一大题选题解析与提示(未完)
  • 通过ts declare包装一个js库
  • 408知识点自检
  • 安全开发指南
  • 彻底连接pip工具
  • 前端框架对比和选择指南
  • 1panel申请https/ssl证书自动续期
  • WPF入门教学二十三 自定义控件开发
  • 若依从redis中获取用户列表
  • 408算法题leetcode--第21天
  • Java每日面试题(JVM)(day15)
  • sentinel微服务部署
  • vue3+PPTXjs 在线ppt预览
  • 基于单片机多功能称重系统设计
  • C++ | Leetcode C++题解之第451题根据字符出现频率排序
  • YOLO11改进|注意力机制篇|引入MLCA轻量级注意力机制
  • Azure Kinect 人体跟踪关节
  • RUP:用例驱动、以架构为中心的迭代增量开发模式
  • 松山湖全球首秀:传祺华为概念车发布
  • 【场景题】秒杀系统设计以及解决方案
  • 如何理解线性回归中的w和b
  • Tableau数据可视化入门
  • Windows暂停更新
  • 【PostgreSQL】入门篇——SELECT、INSERT、UPDATE 和 DELETE 语句,SQL 中最常用的四种操作用法
  • uni-app - - - - -vue3使用i18n配置国际化语言
  • GB28181信令交互流程及Android端设备对接探讨
  • 利用低代码快速搭建电商小程序之商品列表页
  • IPv4与TCP数据包结构解析
  • 使用iTextPDF库设置文字为英文样式
  • CentOS 替换 yum源 经验分享