Animated div or fieldset featuring a multi-step form

I have recently put together a detailed step-by-step guide. Each step is wrapped in its own "fieldset" within a single .html file.

To navigate back and forth, I have incorporated javascript into the process. However, as time goes on, I am noticing that the animations are starting to experience delays.

In the example provided below, everything runs smoothly because there isn't much content involved. So, where might the issue lie when it comes to optimization?

JsFiddle

HTML:

<form id="msform">
    <fieldset id="firstField">   
        <input type="button" name="subject1" class="next action-button" value="Subject1 />
        <input type="button" name="subject2" class="next action-button" value="Subject2 />
        <input type="button" name="subject3" class="next action-button" value="Subject3 />
    </fieldset>
    <fieldset id="subject1">
        <h2>Some text</h2>
        <input type="button" name="prev" class="back action-button" value="Back" />
        <input type="button" name="previous" class="previous action-button" value="Reset" />
     </fieldset>
</form>

Javascript:

....(Javascript code here)....

Answer №1

Have you managed to get the button functioning within a div?

I have downloaded the same "Multi Step Form with Progress Bar using jQuery and CSS3."

I was successful in displaying the fieldsets within divs, but encountered an issue with the button's onclick function not working when placed inside a div.

On one hand, this progresses to the next step:

  <fieldset>
<h2 class="fs-title">Create your account</h2>
<h3 class="fs-subtitle">This is step 1</h3>
<input type="text" name="email" placeholder="Email" />
<input type="password" name="pass" placeholder="Password" />
<input type="password" name="cpass" placeholder="Confirm Password" />
<input type="button" name="next" class="next action-button" value="Next" />

While on the other hand, this does not:

  <fieldset>
<h2 class="fs-title">Create your account</h2>
<h3 class="fs-subtitle">This is step 1</h3>
<input type="text" name="email" placeholder="Email" />
<input type="password" name="pass" placeholder="Password" />
<input type="password" name="cpass" placeholder="Confirm Password" />
<div class="pull-right">
    <input type="button" name="next" class="next action-button" value="Next" />                
</div>

I have tried everything I can think of, including removing animations without success.

To address your question... :)

I modified my JS code to disable (comment out) as much animation as possible and set the duration to 000...

//jQuery time
var current_fs, next_fs, previous_fs; //fieldsets
var opacity; //fieldset properties which we will animate
var animating; //flag to prevent quick multi-click glitches

$(".next").click(function(){
    if(animating) return false;
    animating = true;

    current_fs = $(this).parent();
    next_fs = $(this).parent().next();

    //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+')'});
            current_fs.css({'opacity': opacity});
            //next_fs.css({'left': left, 'opacity': opacity});
            next_fs.css({'opacity': opacity});
        }, 
        duration: 000, 
        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();

    //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 "now"
            //1. scale previous_fs from 80% to 100%
            //scale = 0.8 + (1 - now) * 0.2;
            //2. take current_fs to the right(50%) - from 0%
            //left = ((1-now) * 50)+"%";
            //3. increase opacity of previous_fs to 1 as it moves in
            opacity = 1 - now;
            //current_fs.css({'left': left});
            current_fs.css({'opacity': opacity});
            //previous_fs.css({'transform': 'scale('+scale+')', 'opacity': opacity});
            previous_fs.css({'opacity': opacity});
        }, 
        duration: 000, 
        complete: function(){
            current_fs.hide();
            animating = false;
        }, 
        //this comes from the custom easing plugin
        easing: 'easeInOutBack'
    });
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How to use Javascript to toggle a popup containing an autoplaying Vimeo video

I am looking to create a pop-up window containing a Vimeo video inside. I have a div on my webpage with an id of "showVideo". When this div is clicked, I want to display a pop-up (new div with the id of "opened-video"). The "opened-video" div contains an i ...

"Error 413 Request Entity Too Large" occurs specifically for AJAX POST requests, yet does not apply to standard file uploads

My current hosting environment is a shared package by 1und1 (1and1). Everything runs smoothly on my laptop during testing. Recently, I encountered an issue when sending a relatively large AJAX request to the server (~1.2MB). For some reason, it stopped wo ...

Receive the most recent query in a Nuxt plugin following the completion of page loading

So, here's the issue - I have a plugin containing some functions that are supposed to update URL queries. However, every time I run $global.changePage(2) or $global.changeLimit(2), the console.log(query) outputs an empty object and doesn't show t ...

Separate a string using commas but disregard any commas inside quotation marks

Similar Question: JavaScript code for parsing CSV data There is a string that looks like this: "display, Name" <<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3d49584e497d49584e49135e5250">[email protected]</a> ...

Can the conventional HTML context menu be swapped out for a link context menu instead?

Currently, I am working on developing a custom linkbox component that is similar to the one found on this page: Here is an example of the code: export const Linkbox = ({}) => { const linkRef = useRef(null); return ( // eslint-disable-next-l ...

Is there a way to alter the camera's focal point in THREEJS to focus on a specific object already in the scene?

Currently, I am working with a scene extracted from a THREEJS example (https://threejs.org/examples/webgl_loader_fbx.html) that involves importing and displaying a threejs.json scene. The rendering of the scene works perfectly; I have a grid in place with ...

Navigate back to a previous page on a PHP website

I am working on a PHP program and need help figuring out how to go from page 2 back to page 1 using a button. I tried creating a button on the second page with a value of 1, but it resulted in an error for the user. Can someone guide me on how to achieve ...

Forwarding based on URL/Query Parameters

I'm looking to create a redirect for users based on URL or query parameters, but I'm not sure how to go about it. For example, if the URL is https://www.tamoghnak.tk/redirect?link=https://www.tamoghnak.tk/gobob, I want to redirect to /gobob. If ...

Retrieve all hyperlinks from HTML using C programming

Is there a way to extract all URLs from an HTML document using the C standard library? I attempted to use sscanf() for this purpose, but encountered errors when checking with valgrind. I'm unsure if my code will meet the requirements even after succe ...

The page switch with a jittery effect

Could really use some assistance with this code that has been giving me trouble for quite a while now. It's a simple HTML, CSS, and JS code involving two pages. [The second page overlaps the first by default, but adjusting the z-index of the first p ...

The RSS XML feed causes jQuery Ajax to throw an error in Internet Explorer 9

On my ASPX page, I generate RSS XML in the following format: <?xml version="1.0" encoding="utf-8"?> <rss version="2.0"> <channel> <title>Article Feed</title> <link>http://www.example.com/articles</link> ...

CSS - Customizing the appearance of consecutive child divs

I'm struggling with adjusting the margin between two child divs when they follow each other. The current margin is set at 3rem, but I want it to be 1rem if both child containers have the class "narrow": Is there a way to achieve this without changing ...

Issue with Adding Additional Property to react-leaflet Marker Component in TypeScript

I'm attempting to include an extra property count in the Marker component provided by react-leaflet. Unfortunately, we're encountering an error. Type '{ children: Element; position: [number, number]; key: number; count: number; }' is n ...

CSS class for focusing in jQuery not displayed on control

My goal is to automatically set the focus on the first control in a form as soon as the page loads. However, I've encountered an issue where this works intermittently - sometimes the cursor is not placed in the field, but rather in the address bar. Th ...

unresolved string constant issue with a django template command

I encountered an issue with the code snippet below, which is resulting in an unterminated string literal error: $(function() { $('#addDropdown').click(function() { var $d = $('{{ form |bootstrap }}').fadeIn(). ...

The issue with passing parameters to ajax to trigger an action in .net core 2 persists

I am trying to pass a parameter to a simple action that returns a partial view in a popup, but for some reason the parameters are not being passed and it seems like they are not reaching the action. I don't understand why??? I am using .NET Core 2. ...

access the content of a div element by its class attribute

Within the div element, a value has been set and I am attempting to retrieve this value using its class. However, the code below does not return the desired value. What mistake am I making here? How can I resolve this issue? <div title="Find on Amazo ...

An error occurred due to an unexpected identifier, '_classCallCheck', while the import call was expecting exactly one

Encountering an unexpected identifier '_classCallCheck'. Import call requires precisely one argument. Having trouble with React Native. I have attempted every solution found on the internet, but none proved successful. Is there any way to upgrade ...

Utilize Angular directive to encapsulate JQuery

I am struggling to integrate the jquery codepen provided by mnpenner into an angular directive. This is my first time working with directives and I can't seem to get it functioning... http://codepen.io/mnpenner/pen/mFokd I attempted to add the code ...

An issue arises with React hooks: useMemo and useEffect display a Missing dependency error when attempting to invoke a function

triggerData function is being utilized in multiple functions. However, if I place the function inside the useEffect to prevent missing dependencies, then I am unable to call the triggerData outside of the useEffect i.e., in buildData. How can I resolve the ...