JSFiddle - React, Tailwind, and code Playground
by brightonmike
HTML
<link rel="stylesheet" href="http://jetbookingdirect.com/wp-content/w3tc/min/270f7/default.include.36ccf3.css">
<div id="slidequoteformcontainer" class="gradient">
<div id="steps">
<form id="slidequoteform" name="slidequoteform" action="<?php bloginfo('template_directory'); ?>/contactengine.php" method="post">
<fieldset class="step">
<legend>Personal Details</legend>
<div class="slide">
<fieldset class="fieldrow">
<label>Your full name:</label><input type="text" id="Name" name="name" value="" placeholder="Type in your full name" class="required">
</fieldset>
<fieldset class="fieldrow">
<label>Your email:</label><input type="text" id="Email" name="email" value="" placeholder="Type in your valid email" class="required">
</fieldset>
<fieldset class="fieldrow">
<label>Your number:</label><input type="text" id="Number" name="number" value="" placeholder="Type your number incl. Country code" class="required">
</fieldset>
<fieldset class="fieldrow">
<label>Number of Passengers:</label><input type="text" id="pax" name="pax" value="" placeholder="Number of...
JavaScript
$(function() {
/*
number of fieldsets
*/
var fieldsetCount = $('#slidequoteform').children().length;
/*
current position of fieldset / navigation link
*/
var current = 1;
/*
sum and save the widths of each one of the fieldsets
set the final sum as the total width of the steps element
*/
var stepsWidth = 0;
var widths = new Array();
$('#steps .step').each(function(i){
var $step = $(this);
widths[i] = stepsWidth;
stepsWidth += $step.width();
});
$('#steps').width(stepsWidth);
/*
to avoid problems in IE, focus the first input of the form
*/
$('#slidequoteform').children(':first').find(':input:first').focus();
/*
show the navigation bar
*/
$('#navigation').show();
/*
when clicking on a navigation link
the form slides to the corresponding fieldset
*/
$('#navigation a').bind('click',function(e){
var $this = $(this);
var prev = current;
$this.closest('ul').find('li').removeClass('selected');
$this.parent().addClass('selected');
/*
we store the position of the link
in the current variable
*/
current = $this.parent().index() + 1;
/*
animate / slide to the next or to the corresponding
fieldset. The order of the links in the navigation
is the order of the fieldsets.
Also, after sliding, we trigger the focus on the first
input element of the new fieldset
If we clicked on the last link (confirmation), then we validate
all the fieldsets, otherwise we validate the previous one
before the form slided
*/
$('#steps').stop().animate({
marginLeft: '-' + widths[current-1] + 'px'
},500,function(){
if(current == fieldsetCount)
...