adding the progress bar to existing multi step form

时间:2016-11-12 05:54:37

标签: javascript html css

please I have troubling with adding this progress bar to a multi step registration form, I would be very much glad if any one can help me in this.

HTML

<!DOCTYPE html>
<html >
<head>
    <meta charset="UTF-8">
    <title>Form Progress Bar</title>

    <link href='http://fonts.googleapis.com/css?family=Open+Sans'rel='stylesheet' type='text/css'>     
    <link rel="stylesheet" href="css/style.css">
</head>

<body>
    <div class="progress">
        <div class="circle done">
            <span class="label">1</span>
            <span class="title">Personal</span>
        </div>
        <span class="bar done"></span>
        <div class="circle done">
            <span class="label">2</span>
            <span class="title">Address</span>
        </div>
        <span class="bar half"></span>
        <div class="circle active">
            <span class="label">3</span>
            <span class="title">Payment</span>
        </div>
        <span class="bar"></span>
        <div class="circle">
            <span class="label">4</span>
            <span class="title">Review</span>
        </div>
        <span class="bar"></span>
        <div class="circle">
            <span class="label">5</span>
            <span class="title">Finish</span>
        </div>
    </div>
    <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
    <script src="js/index.js"></script>
</body>
</html>

JavaScript

var i = 1;
$('.progress .circle').removeClass().addClass('circle');
$('.progress .bar').removeClass().addClass('bar');
setInterval(function() {
    $('.progress .circle:nth-of-type(' + i + ')').addClass('active');

    $('.progress .circle:nth-of-type(' + (i-1) + ')').removeClass('active').addClass('done');

    $('.progress .circle:nth-of-type(' + (i-1) + ') .label').html('&#10003;');

    $('.progress .bar:nth-of-type(' + (i-1) + ')').addClass('active');

    $('.progress .bar:nth-of-type(' + (i-2) + ')').removeClass('active').addClass('done');

    i++;

    if (i==0) {
        $('.progress .bar').removeClass().addClass('bar');
        $('.progress div.circle').removeClass().addClass('circle');
        i = 1;
    }
}, 1000);

CSS

*, *:after, *:before {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: "Open Sans";
}

/* Form Progress */
.progress {
    width: 1000px;
    margin: 20px auto;
    text-align: center;
}

.progress .circle,
.progress .bar {
    display: inline-block;
    background: #fff;
    width: 40px; height: 40px;
    border-radius: 40px;
    border: 1px solid #d5d5da;
}

.progress .bar {
    position: relative;
    width: 80px;
    height: 6px;
    margin: 0 -5px 17px -5px;
    border-left: none;
    border-right: none;
    border-radius: 0;
}

.progress .circle .label {
    display: inline-block;
    width: 32px;
    height: 32px;
    line-height: 32px;
    border-radius: 32px;
    margin-top: 3px;
    color: #b5b5ba;
    font-size: 17px;
}

.progress .circle .title {
    color: #b5b5ba;
    font-size: 13px;
    line-height: 30px;
    margin-left: -5px;
}

/* Done / Active */
.progress .bar.done,
.progress .circle.done {
    background: #eee;
}

.progress .bar.active {
    background: linear-gradient(to right, #EEE 40%, #FFF 60%);
}

.progress .circle.done .label {
    color: #FFF;
    background: #8bc435;
    box-shadow: inset 0 0 2px rgba(0,0,0,.2);
}

.progress .circle.done .title {
    color: #444;
}

.progress .circle.active .label {
    color: #FFF;
    background: #0c95be;
    box-shadow: inset 0 0 2px rgba(0,0,0,.2);
}

.progress .circle.active .title {
    color: #0c95be;
}

I just want to know how to link this progress bar to a multi step form. I tried several times, but did not work. This code is working very well but when I include multi step form with fieldsets it doesn't work. Any help would be highly appreciated as I want to hand over this project to school. Thank you..

0 个答案:

没有答案