html、css、js实现步骤条(学习篇)

效果图
在这里插入图片描述

1、html部分

<div class="modal-body">
    <!-- 步骤条 -->
	<div class="steps">
         <div class="step">
              <div class="step-head">
              	<div class="step-line"></div>
              	<div class="step-icon">1</div>
          	  </div>
              <div class="step-main">身份认证</div>
          </div>
          <div class="step">
                <div class="step-head">
                     <div class="step-line"></div>
                     <div class="step-icon"> 2</div>
                 </div>
                 <div class="step-main">设置操作</div>
           </div>
           <div class="step">
                <div class="step-head">
                     <div class="step-icon">3</div>
                </div>
                <div class="step-main">完成</div>
           </div>
    </div>
    <!-- 身份认证内容 -->
    <div class="step_1" id="step_1">
         <div class="step1_icon"></div>
         <div class="right_register">
              <span>当前手机号:</span>
              <span id="step1_phone"></span>
         </div>
         <div class="step_code">
               <input type="input" name="" id="step1_value" value="" autocomplete="off" />
               <p id="step1_validate" style="color: #f56c6c;margin:0;float: left;"></p>
               <button class="code" id="yanzhengb" onclick="handelAuthCode()">获取验证码</button>
         </div>
         <div class="step_submit" onclick="addStep()">
              <input type="button" value="提交认证" />
         </div>
     </div>
     <!-- 设置操作 -->
     <div class="step_2" id="step_2">
          <div class="step2_title">设置绑定手机</div>
          <div class="step2_phone">
          <input type="input" name="" id="step2_value1" value="" autocomplete="off" />
          <p id="step2_validate1" style="margin:0;margin-left: 140px;color: #f56c6c;float: left;"></p>
     </div>
     <div class="step2_code">
         <input type="input" name="" id="step2_value2" value="" autocomplete="off" />
         <p id="step2_validate2" style="color: #f56c6c;margin:0;float: left;"></p>
         <button class="code authbtn" id="yanzhengb1" onclick="handelAuthCode1()">获取验证码</button>
     </div>
     <div class="step_submit" onclick="addStep()" style="margin-top: 20px;">
         <input type="button" value="提交绑定" />
     </div>
     </div>
     <!-- 完成 -->
     <div class="step_3" id="step_3">
          <div class="step3_succes">手机号绑定成功</div>
          <div class="step_submit" onclick="addStep()">
               <input type="button" value="重新登录" />
          </div>
     </div>
</div>

2、css部分

/* 步骤条样式 */

.step {
    position: relative;
    vertical-align: top;
    display: inline-block;
    margin: 20px 50px 20px 80px;
}

.step-head {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    line-height: 30px;
    text-align: center;
    vertical-align: top;
    color: #333;
    font-size: 14px;
    border: 2px solid #D9D9D9;
    z-index: 10000;
    cursor: pointer;
}

.step-main {
    font-size: 12px;
    color: #48576a;
    margin-top: 15px;
    font-size: 14px;
    color: #444444;
}

.step-line {
    position: absolute;
    top: 15px;
    height: 2px;
    left: 30px;
    right: -134px;
    display: inline-block;
    background-color: #bfcbd9;
    z-index: 10000;
}

.step-circle {
    margin: 4px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: #bfcbd9;
}

.is-sucess>.step-head {
    border-color: #60B34F;
    background: #60B34F;
    color: #FFFFFF;
}

.is-sucess>.step-head .step-circle {
    background-color: #2f318e;
}

.is-sucess>.step-head>.step-line {
    background-color: #60B34F;
}

.last-sucess>.step-head {
    color: #ffffff;
    border-color: #60B34F;
    background: #60B34F;
}

.last-sucess>.step-head .step-circle {
    background-color: #2f318e;
}

.modal .modal-dialog .modal-content .modal-body .step_1 {
    display: block;
}

.modal .modal-dialog .modal-content .modal-body .step_1 .step1_icon {
    width: 46px;
    height: 46px;
    background: url('../images/step1.svg') no-repeat;
    margin-left: 255px;
    margin-top: 10px;
}

.modal .modal-dialog .modal-content .modal-body .step_1 .right_register {
    margin-left: 195px;
    margin-top: 25px;
}

.modal .modal-dialog .modal-content .modal-body .step_1 .step_code {
    position: relative;
    width: 300px;
    margin-left: 140px;
}

.modal .modal-dialog .modal-content .modal-body .step_1 .step_code input {
    border: 1px solid #DDDDDD;
    width: 300px;
    height: 40px;
    margin-top: 30px;
    padding-left: 10px;
}

.modal .modal-dialog .modal-content .modal-body .step_1 .step_code a {
    width: 82px;
    height: 30px;
    line-height: 30px;
    text-align: center;
    border-radius: 5px;
    background: #E6E6E6;
    color: #444444;
    position: absolute;
    text-decoration: none;
    top: 35px;
    right: 5px;
}

.modal .modal-dialog .modal-content .modal-body .step_1 .step_code p {
    color: red;
}

.modal .modal-dialog .modal-content .modal-body .step_submit {
    background: #4E9BFF;
    color: #ffffff;
    width: 300px;
    height: 42px;
    line-height: 42px;
    margin-left: 140px;
    margin-top: 20px;
    text-align: center;
    border-radius: 5px;
    margin-bottom: 40px;
    cursor: pointer;
}


/* 设置操作 */

.modal .modal-dialog .modal-content .modal-body .step_2 {
    display: none;
}

.modal .modal-dialog .modal-content .modal-body .step_2 .step2_title {
    font-size: 14px;
    font-weight: 700;
    margin-left: 140px;
    margin-top: 30px;
}

.modal .modal-dialog .modal-content .modal-body .step_2 .step2_phone {
    margin-top: 10px;
    margin-bottom: 20px;
}

.modal .modal-dialog .modal-content .modal-body .step_2 .step2_phone input {
    border: 1px solid #DDDDDD;
    width: 300px;
    height: 40px;
    margin-left: 140px;
    padding-left: 10px;
}

.modal .modal-dialog .modal-content .modal-body .step_2 .step2_code {
    width: 300px;
    height: 40px;
    margin-top: 15px;
    margin-left: 140px;
    position: relative;
}

.modal .modal-dialog .modal-content .modal-body .step_2 .step2_code input {
    border: 1px solid #DDDDDD;
    width: 300px;
    height: 40px;
    padding-left: 10px;
}

.modal .modal-dialog .modal-content .modal-body .step_2 .step2_code a {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 82px;
    height: 30px;
    line-height: 30px;
    text-align: center;
    background: #CCCCCC;
    border-radius: 3px;
    color: #444444;
    text-decoration: none;
}


/* 完成 */

.modal .modal-dialog .modal-content .modal-body .step_3 .step3_succes {
    font-weight: 700;
    font-style: normal;
    font-size: 16px;
    margin-top: 70px;
    margin-bottom: 100px;
    margin-left: 225px;
}

.modal .modal-dialog .modal-content .modal-body .step_3 {
    display: none;
}

3、js部分

// 步骤条
var steps = $(".step");
var stepIndex = 0;
setStep(stepIndex);
// 动态添加class
function setStep(stepIndex) {
    $(steps).removeClass("is-sucess");
    $(steps).removeClass("last-sucess");
    for (var i = 0; i <= stepIndex; i++) {
        var step = steps[i];
        if (i < stepIndex) {
            $(step).addClass("is-sucess");
        } else {
            $(step).addClass("last-sucess");
        }
    }
    $('#step_1').css('display', 'none');
    $('#step_2').css('display', 'none');
    $('#step_3').css('display', 'none');
    //判断stepIndex,根据stepIndex显示对应的部分
    if (stepIndex == 0) {
        $('#step_1').css('display', 'block');
    }
    if (stepIndex == 1) {
        $('#step_2').css('display', 'block');
    }
    if (stepIndex == 2) {
        $('#step_3').css('display', 'block');
    }
}
// 重置
function clearSteps() {
    stepIndex = -1;
    setStep(stepIndex);
}
//下一步
function addStep(addnum) {
    if (stepIndex == 0) {
       //发送接口,获取数据或者提交数据
       stepIndex = 1;
       setStep(stepIndex);
    } else if (stepIndex == 1) {
        //发送接口,获取数据或者提交数据
       stepIndex = 2;
       setStep(stepIndex);        
    } else {
    	 //stepIndex = 2 执行这部分	
   		 //发送接口,获取数据或者提交数据
    }
}
  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 如何实现简易轮播图? 要实现简易轮播图,我们需要使用 HTMLCSSJavaScript。 1. 首先,在 HTML 中创建轮播图的容器元素,如 <div class="swiper-container"></div>。 2. 在 CSS 中设置容器元素的宽度和高度,以及每个轮播项(即图片)的宽度和高度。 3. 在 JavaScript 中获取容器元素和所有轮播项的元素,并将它们保存为变量。 4. 在 JavaScript 中设置一个定时器,每隔一定时间就切换下一张轮播项的显示。 5. 切换轮播项时,需要动态修改容器元素的 left 值,以使下一张轮播项出现在视图中。 6. 在 JavaScript 中处理轮播项的无限循环,即最后一张轮播项切换到第一张轮播项时,容器元素的 left 值需要设置为 0。 7. 最后,可以添加一些 UI 控件,如向左和向右箭头,用于手动切换轮播项的显示。 通过以上步骤,我们可以实现一个简易的轮播图效果。 ### 回答2: 在Web开发中,轮播图是非常常见的一种交互效果。轮播图通常由多张图片、标题、文本等内容组成,并自动或手动地在页面上轮播展示。本文将介绍使用HTMLCSSJavascript实现简易轮播图的方法。 首先,我们需要先设计页面布局和轮播图的样式。在HTML中,我们可以使用一个div元素作为轮播图的容器,并在其中创建多个子元素,每个子元素代表一张轮播图片。同时,在每个子元素上还可以添加标题、文本等元素。具体代码如下: ``` <div class="slider"> <div class="slider__item"> <img src="img1.jpg" alt="Slide 1"> <h3>Slide 1</h3> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p> </div> <div class="slider__item"> <img src="img2.jpg" alt="Slide 2"> <h3>Slide 2</h3> <p>Nullam bibendum quam sed enim ultrices, ac pharetra tellus bibendum.</p> </div> <div class="slider__item"> <img src="img3.jpg" alt="Slide 3"> <h3>Slide 3</h3> <p>Etiam eget ligula in lectus varius porta quis sit amet quam.</p> </div> </div> ``` 在CSS中,我们可以设置轮播图容器的宽度、高度、背景色等属性,并将每个子元素设置为绝对定位,以实现叠加效果。具体样式代码如下: ``` .slider { width: 100%; height: 500px; position: relative; background-color: #f5f5f5; overflow: hidden; } .slider__item { position: absolute; top: 0; left: 0; right: 0; bottom: 0; opacity: 0; transition: opacity 1s ease-in-out; } .slider__item.active { opacity: 1; } ``` 在Javascript中,我们可以通过设置定时器来控制轮播图片的切换。具体做法是定义一个变量index表示当前展示的图片序号,在定时器中每隔一段时间将index自增1,并将当前图片的样式设置为.active。同时,如果index超过最大值,则将index重置为0,并从第一张图片重新开始轮播。具体Javascript代码如下: ``` let index = 0; const slides = document.querySelectorAll(".slider__item"); const maxIndex = slides.length - 1; setInterval(() => { slides[index].classList.remove("active"); index = (index === maxIndex) ? 0 : (index + 1); slides[index].classList.add("active"); }, 5000); ``` 通过以上步骤,我们就可以实现一个基础的轮播图效果了。当然,为了增强用户的体验,我们还可以添加其他交互效果,比如滑动、点击等。同时,我们也需要注意优化代码的性能和可读性,以便实现更复杂、完善的轮播图效果。 ### 回答3: 在网页设计中,轮播图被广泛应用,它可以用于展示多张图片或图片与文字的综合效果。本文将介绍如何使用HTMLCSSJavaScript实现简易轮播图。 首先,我们需要创建一个基本的HTML结构,包含一个div容器和多个图片元素。这些图片元素将被放置在div容器中,并且使用CSS调整它们的样式和位置。例如: ``` <div class="carousel"> <img src="image1.jpg"> <img src="image2.jpg"> <img src="image3.jpg"> </div> ``` 接下来,我们使用CSS调整div容器和图片元素的样式,创建一个适合展示轮播图的视觉效果。根据需要,可以使用float、width、height、margin和padding等属性调整元素的位置和间距。例如: ``` .carousel { width: 600px; height: 400px; margin: 0 auto; overflow: hidden; position: relative; } .carousel img { width: 100%; height: 100%; position: absolute; top: 0; left: 0; } ``` 在这里,我们将div容器的宽度设置为600像素,高度设置为400像素。将margin设置为0 auto,使其水平居中。通过设置overflow为hidden,实现图片元素的裁剪。将图片元素的宽度和高度分别设置为100%,以填充整个div容器。使用position:absolute属性和top、left属性将图片堆叠在一起。 最后,我们使用JavaScript函数和事件来实现轮播图的自动切换。我们可以使用setInterval函数在一定的时间间隔之后轮流显示每个图片元素。例如: ``` let slideIndex = 0; setInterval(() => { let slides = document.querySelectorAll('.carousel img'); slides[slideIndex].style.display = "none"; slideIndex = (slideIndex + 1) % slides.length; slides[slideIndex].style.display = "block"; }, 2000); ``` 在这里,我们首先创建一个slideIndex变量,用于跟踪显示的图片索引。使用setInterval函数创建一个按照固定时间间隔循环运行的匿名函数,在匿名函数中使用querySelectorAll函数选择所有图片元素,并在slideIndex变量中更新索引值。接着,在当前图片上应用style.display = "none"将其隐藏,将下一张图片显示出来。 综上所述,HTMLCSSJavaScript实现简易轮播图的三个必要组成部分。通过结合这三种技术,我们可以轻松地创建出一个具有自动切换功能的轮播图。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值