JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js"></script>
<div id="variable-div">
<!-- multistep form -->
<form id="msform">
<!-- progressbar -->
<ul id="progressbar">
<li class="active">Description</li>
<li>Preferences</li>
<li>Done!</li>
</ul>
<!-- fieldsets -->
<fieldset class="container">
<div>
<p class="fs-question">Question title</p>
<textarea name="1" placeholder="e.g." rows="3"></textarea>
<p class="fs-question">Question 2</p>
<input type="text" name="2" placeholder="e.g." />
<input type="button" name="next" class="next action-button" value="Next" />
</div>
</fieldset>
<fieldset>
<p class="fs-title">Fieldset title</p>
<p class="fs-subtitle">subtitle</p>
<p class="fs-question">Question 3</p>
<input type="text" name="3" placeholder="e.g." />
<p class="fs-question">Question 4</p>
<input type="text" name="4" placeholder="e.g." />
<input type="button" name="previous" class="previous action-button" value="Previous" />
<input type="button" name="next" class="next action-button" value="Next" />
</fieldset>
<fieldset>
<p class="fs-title">title</p>
<h3 class="fs-subtitle">subtitle</h3>
<p class="fs-question">Question</p>
<textarea name="other" placeholder="e.g."></textarea>
<p class="fs-question">question 5</p>
<input type="text" name="5" placeholder="e.g" />
<p class="fs-question">question 6</p>
<input type="password" name="Password" placeholder="e.g" />
<p class="fs-question">question 7</p>
<input type="text" name="7" placeholder="e.g" />
<p class="fs-question">question 8</p>
<input type="text" name="8" placeholder="e.g" />
<input type="button" name="previous" class="previous action-button" value="Previous" />
<input type="submit" name="submit" class="submit action-button" value="Submit and create account" />
...
CSS
/*custom font*/
@import url(http://fonts.googleapis.com/css?family=Montserrat);
/*basic reset*/
body {
font-family: montserrat, arial, verdana;
}
/*form styles*/
#msform {
width: 800px;
margin: 0px auto;
text-align: center;
position: relative;
padding-bottom: 100px;
}
#msform fieldset {
margin-left:auto;
margin-right:auto;
background: white;
border: 0 none;
border-radius: 10px;
box-shadow: 0 0 15px 1px rgba(0, 0, 0, 0.2);
padding: 20px 60px;
margin-bottom: 100px;
width: 85%;
/*stacking fieldsets above each other*/
position: absolute;
}
/*Hide all except first fieldset*/
#msform fieldset:not(:first-of-type) {
display: none;
}
/*inputs*/
#msform input, #msform textarea {
padding: 15px;
border: 1px solid #ccc;
border-radius: 3px;
margin-bottom: 10px;
width: 80%;
box-sizing: border-box;
font-family: montserrat;
color: #2C3E50;
font-size: 13px;
margin: 0;
}
/*buttons*/
#msform .action-button {
width: auto;
min-width:100px;
background: #27AE60;
font-weight: bold;
color: white;
border: 0 none;
border-radius: 1px;
cursor: pointer;
padding: 10px 20px;
margin: 10px 5px;
}
#msform .action-button:hover, #msform .action-button:focus {
box-shadow: 0 0 0 2px white, 0 0 0 3px #27AE60;
}
/*headings*/
.fs-question {
text-align: left;
padding: 10px 60px;
margin: 0px;
}
.fs-title {
font-size: 15px;
text-transform: uppercase;
color: #2C3E50;
margin-bottom: 10px;
padding: 0px;
margin: 0px;
}
.fs-subtitle {
font-weight: normal;
font-size: 13px;
color: #666;
margin-bottom: 20px;
padding: 0px;
margin: 0px;
}
/*progressbar*/
#progressbar {
margin-bottom: 30px;
overflow: hidden;
/*CSS counters to number the steps*/
counter-reset: step;
}
#progressbar li {
list-style-type: none;
color: white;
text-transform: uppercase;
font-size: 13px;
width: 33.33%;
float: left;
position: relative;
text-shadow: 0px 1px 2px #000;
}
#progressbar li:before {
content: counter(step);
counter-increment: step;
width: 20px;
line-height:...
JavaScript
//jQuery time
var current_fs, next_fs, previous_fs; //fieldsets
var left, opacity, scale;
//fieldset properties which we will animate
var animating; //flag to prevent quick multi-click glitches
var mainDiv = $( '#variable-div' );
var currentFieldset = $('fieldset');
mainDiv.css('marginBottom', (currentFieldset.height() + 5) + 'px');
$(".next").click(function(){
if(animating) return false;
animating = true;
current_fs = $(this).parent();
next_fs = $(this).parent().next();
mainDiv.css('marginBottom', (next_fs.height() + 5) + 'px');
//activate next step on progressbar using the index of next_fs
$("#progressbar li").eq($("fieldset").index(next_fs)).addClass("active");
//show the next fieldset
next_fs.show();
//hide the current fieldset with style
current_fs.animate({opacity: 0}, {
step: function(now, mx) {
//as the opacity of current_fs reduces to 0 - stored in "now"
//1. scale current_fs down to 80%
scale = 1 - (1 - now) * 0.2;
//2. bring next_fs from the right(50%)
left = (now * 50)+"%";
//3. increase opacity of next_fs to 1 as it moves in
opacity = 1 - now;
current_fs.css({'transform': 'scale('+scale+')'});
next_fs.css({'left': left, 'opacity': opacity});
},
duration: 800,
complete: function(){
current_fs.hide();
animating = false;
},
//this comes from the custom easing plugin
easing: 'easeInOutBack'
});
});
$(".previous").click(function(){
if(animating) return false;
animating = true;
current_fs = $(this).parent();
previous_fs = $(this).parent().prev();
mainDiv.css('marginBottom', (previous_fs.height() + 5) + 'px');
//de-activate current step on progressbar
$("#progressbar li").eq($("fieldset").index(current_fs)).removeClass("active");
//show the previous fieldset
previous_fs.show();
//hide the current fieldset with style
current_fs.animate({opacity: 0}, {
step: function(now, mx) {
//as the opacity of current_fs reduces to 0 - stored in...