Mutli-step form using GSAP

Developer
Size
4,226 Kb
Views
52,624

How do I make an mutli-step form using gsap?

A snippet of a multi-step form that I created with greensock(gsap). I am newer to js so I believe the js can be refactored, but I tried to connect smaller functions together to attempt to dry out the code. Any help would be appreciated. . What is a mutli-step form using gsap? How do you make a mutli-step form using gsap? This script and codes were developed by Chris Maki on 12 August 2022, Friday.

Mutli-step form using GSAP Previews

Mutli-step form using GSAP - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>mutli-step form using GSAP</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div class="form-wrapper"> <div id="progress"> <div class="circle-1 circle active"></div> <div class="circle-2 circle"></div> <div class="circle-3 circle"></div> </div> <form id="mst-form" action=""> <fieldset class="field-1"> <label for="one" class="form-label anim-each">Field One</label> <input type="text" id="one" class="el-margin anim-each"> <label for="two" class="form-label anim-each">Field Two</label> <input type="text" id="two" class="el-margin anim-each"> <label for="three" class="form-label anim-each">Field Two</label> <input type="text" id="three" class="el-margin anim-each" > <div class="rt-btn-holder btn-fade"> <button class="ghost-btn weight-thin btn-font-size next-1">next</button> </div> </fieldset> <fieldset class="field-2"> <label for="four" class="form-label anim-each">Field Four</label> <input type="text" id="four" class="el-margin anim-each"> <label for="five" class="form-label anim-each">Field Five</label> <input type="text" id="five" class="el-margin anim-each"> <label for="six" class="form-label anim-each">Field Six</label> <input type="text" id="six" class="el-margin anim-each" > <div class="lft-btn-holder btn-fade"> <button class="ghost-btn weight-thin btn-font-size prev-1">prev</button> </div> <div class="rt-btn-holder btn-fade"> <button class="ghost-btn weight-thin btn-font-size next-2">next</button> </div> </fieldset> <fieldset class="field-3"> <label for="seven" class="form-label anim-each">Field Seven</label> <input type="text" id="seven" class="el-margin anim-each"> <label for="eight" class="form-label anim-each">Field Eight</label> <input type="text" id="eight" class="el-margin anim-each"> <label for="nine" class="form-label anim-each">Field Nine</label> <input type="text" id="nine" class="el-margin anim-each" > <div class="lft-btn-holder btn-fade"> <button class="ghost-btn weight-thin btn-font-size prev-2">prev</button> </div> <div class="rt-btn-holder btn-fade"> <input type="submit" name="submit" class="ghost-btn weight-thin btn-font-size submit"> </div> </fieldset> </form> </div> <script src='https://cdnjs.cloudflare.com/ajax/libs/gsap/1.19.0/TweenMax.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Mutli-step form using GSAP - Script Codes CSS Codes

@import url('https://fonts.googleapis.com/css?family=Open+Sans:300,400,700');
html { height: 100%; padding: 0; margin: 0;
}
body {	background-color: #324c5b;	color: #fff; display: -webkit-box; display: -ms-flexbox; display: flex; -webkit-box-orient: vertical; -webkit-box-direction: normal; -ms-flex-direction: column; flex-direction: column; -webkit-box-pack: center; -ms-flex-pack: center; justify-content: center;	font-weight: 100;	font-size: 1em;	font-family: 'Open Sans', sans-serif;	overflow: hidden;	overflow-y: scroll;	min-height: 100%;
}
.form-wrapper { max-width: 1000px; margin: 0 auto; padding: 0 2em;
}
/********************* Button Styles
*********************/
.ghost-btn { background: transparent; border: 2px solid white; border-radius: 4px; color: white; padding: .2em 2em; text-transform: uppercase; font-family: 'Open Sans', sans-serif; -webkit-transition: .25s ease; transition: .25s ease;
}
.ghost-btn:hover { background-color: white; color: #324c5b;
}
.rt-btn-holder {	float: right;
}
.lft-btn-holder { float: left;
}
.opening-btn {	font-size: .8em;
}
.btn-font-size { font-size: 2em;
}
/************** Form
**************/
#progress { counter-reset: circle; text-align: center; overflow: hidden; display: -webkit-box; display: -ms-flexbox; display: flex; -webkit-box-pack: center; -ms-flex-pack: center; justify-content: center; margin-bottom: 2em
}
.circle { background-color: gray; border-radius: 50%; color: #283d4a; font-size: 1.5em; font-weight: 500; margin: 0 .8em; position: relative; height: 50px; width: 50px;
}
.circle:before { content: counter(circle);	counter-increment: circle; position: absolute; top: 10px; left: 0; right: 0
}
.circle.active {	background-color: white;
}
fieldset { border: none; max-width: 1200px;
}
label {
/* clear: both; */
/* display: block; */
}
input[type="text"] { background: transparent; border: 0; border-bottom: 2px solid #aaaaaa; color: #e5e5e5; font-family: 'Open Sans', sans-serif; font-size: 1.8em; font-weight: 100; outline: none; padding: 0 0 .25em .15em; width: 100%;
}
input[type="text"]:focus { border: 0; border-bottom: 2px solid white;
}
.el-margin { margin: 0 0 1.8em ;
}
.form-label { font-size: 1.9em; margin-bottom: .25em;
}
.hidden-fields {	opacity: 0;
}
.hide-fields { opacity: 0;
}
/**************** Fieldsets
****************/
fieldset { min-height: 500px;
}
.field-2, .field-3 { display: none;
}

Mutli-step form using GSAP - Script Codes JS Codes

(function(){
'use strict'; var field1 = ('.field-1'), field2 = ('.field-2'), field3 = ('.field-3'), circle1 = ('.circle-1'), circle2 = ('.circle-2'), circle3 = ('.circle-3');
//var tween = new TimelineMax();
var tween = new TimelineLite();
//Screen One
function screenOne(){ var next = document.querySelector('.next-1'); next.addEventListener('click', function(e) { e.preventDefault(); //circles rotate backwards and previous number is highlighted with .active class and removed from next circle (currCircle, nextCircle) nextCircle(circle1, circle2); //When NEXT button is clicked the next fieldset shows and the previous hides (prevField, nextField) nextFieldSet(field1, field2); });
}screenOne();
//Screen Two
function screenTwo(){ var next = document.querySelector('.next-2'), prev = document.querySelector('.prev-1'); next.addEventListener('click', function(e) { e.preventDefault(); //circles rotate backwards and previous number is highlighted with .active class and removed from next circle (currCircle, nextCircle) nextCircle( circle2, circle3); //When NEXT button is clicked the next fieldset shows and the previous hides (prevField, nextField) nextFieldSet(field2, field3); }); /**How could I or should I combine these into the same tween--this is exhibiting some strange behavior. I **assume this because each function`previousCircle` && `previouosFieldSet` have seperate tweens **Also could I just reverse the above functions `nextCircle` && `nextFieldset` instead of creating the **below functions? **Thanks to anyone for help on this!!!!:) */ prev.addEventListener('click', function(e) { e.preventDefault(); //.active class and removed prom next circle (prevCircle, currCircle) previousCircle(circle1, circle2); //next fieldset shows and the previous hides (prevField, currField) previousFieldSet(field1, field2); });
}screenTwo();
//Screen Six
function screenThree(){ var prev = document.querySelector('.prev-2'); prev.addEventListener('click', function(e) { e.preventDefault(); //.active class and removed prom next circle (prevCircle, currCircle) previousCircle(circle2, circle3); //Prev fieldset shows and the previous hides (prevField, currField) previousFieldSet(field2, field3); });
}screenThree();
//When NEXT button is clicked the next fieldset shows and the previous hides
function nextFieldSet(currField, nextField){ var each = ('.anim-each'); var btnFAde = ('.btn-fade'); //this seems off to me to have display: 'none' and opacity: 0 but it was the only waht to get a smooth fade tween .to(currField, .1, {opacity:0, display: 'none', y:-100}) .to(nextField, .1, {display: 'block', opacity: 1}) .staggerFrom(each, .25, {opacity: 0, y:100}, .1) .from(btnFAde, .1, {opacity: 0}, '-=.5');
}
//When NEXT button is clicked the next fieldset shows and the previous hides
function previousFieldSet(prevField, currField){ var btnFAde = ('.btn-fade'); tween.to(currField, .25, {opacity:0, display: 'none', y: 0}) .to(prevField, .25, {display: 'block', opacity: 1, y:0}) .to(btnFAde, .1, {opacity: 1});
}
/*When PREV button is clicked circles in the progress section rotate backwards and **previous number is highlighted with .active class and removed prom next circle
*/
function previousCircle(prevCircle, currCircle) { tween.to(prevCircle, .15, {rotationY: -360, className: '+=active'}) .to(currCircle, .15, {rotationY: -360, className: '-=active'});
}
/*When NEXT button is clicked circles in the progress section rotate forwards and the **next number is highlighted with .active class and removoed from previous circle
*/
function nextCircle(currCircle, nextCircle) { tween .to(currCircle, .15, {rotationY: 360, className: '-=active'}) .to(nextCircle, .15, {rotationY: 360, className: '+=active'});
}
}()); //wrapper
Mutli-step form using GSAP - Script Codes
Mutli-step form using GSAP - Script Codes
Home Page Home
Developer Chris Maki
Username chrisMaki
Uploaded August 12, 2022
Rating 3
Size 4,226 Kb
Views 52,624
Do you need developer help for Mutli-step form using GSAP?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Chris Maki (chrisMaki) Script Codes
Create amazing marketing copy with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!