Implement a delay in JavaScript functionality by using a switch class

Here's what I'm trying to achieve:

  1. Change the class of the div with ID info from col-lg-12 to col-lg-6 with a sliding effect
  2. After completing the first action, slide down the div with ID project

Currently, action 2 is happening simultaneously with action 1, without any delay. Below is my code snippet:

$(document).ready(function(){

    $("#project").hide();

    $("#phone").blur(function(){

        if($("#name").val() > ""){
            if($("#business").val() > ""){
                if($("#email").val() > ""){
                    if($("#phone").val() > ""){

                        $("#info").switchClass("col-lg-12", "col-lg-6", 500);
                        $("#project").slideDown(800).delay(800).fadeIn(800);
                    }
                }
            }
        }

    });

});

Answer №1

Have you considered implementing a callback for the last effect in your chain, specifically the switchClass function? This approach could help with staging your operations by ensuring that the chained functions occur after the slide-in effect. By utilizing complete callbacks, you can better control the sequence of events.


$("#info").switchClass("col-lg-12", "col-lg-6", 500, function(){
  $("#project").slideDown(800).delay(800).fadeIn(800);
});

I made some adjustments to align with your staging requirements.

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

What is the best way to iterate through an ID using jQuery?

After pulling the list of doctors in my area from the database and displaying it on my webpage, I now want to load each doctor's "About" content inside a Bootstrap modal. I added an "about" column within the same database table where the doctors' ...

The oddity of a lone quotation mark trying to break

var x = "Test \'" > undefined var y = "Test '" > undefined x === y > true x > "Test '" https://i.stack.imgur.com/ZrHo5.jpg Aha! Both of these strings are actually equal (as shown in the example code) - but why is that the ...

Creating audio streams using react-player

I am currently working on integrating the react-player component from CookPete into my website. However, I am facing a challenge in setting up multiple audio streams. Additionally, I want to include both DASH and HLS video streams but adding them as an arr ...

The absence of an index signature in GenericType is causing a missing declaration of the expected key/value type in Flow type

I am encountering difficulties accessing an object property dynamically with a Generic Type. Below is the code snippet: import React, { useState } from 'react' function useForm<FormValues>(initialValues: FormValues) { const [formValue ...

Issues with Dropzone.js addRemoveLinks functionality being unresponsive

Hello, I'm having some trouble working with the custom options in Dropzone.js. Despite setting it to true, the remove links are not showing up as they should. I'm not sure if I'm approaching this the right way or what exactly is causing this ...

Obtaining the total count by using getGridParam() following the execution of trigger("reloadGrid")

I am trying to retrieve the total count of records after conducting a search. However, I am encountering an issue where getGridParam("records") does not return the correct value after trigger("reloadGrid"). Below is the code that I am using: goSearch : f ...

Using Javascript to Extract Data from a JSON Array

I am working with a straightforward Json array and need to retrieve the following: The total number of items in the array. The list of entries ordered by id. Below is an example of the array: {"error":false,"error_msg":"","body": {"records":[{"name":"A ...

Triggering a JavaScript function upon the alteration of a Dojo auto-complete widget's value

I'm encountering an issue with calling a javascript function when the value of a Dojo auto completer changes. Despite trying to call the function through the "onChange" attribute, it doesn't work as expected. Within the javascript function, my ...

Unable to display the "detailed form" on the next page pagination of the DataTables

Every time I click on the class="detail" button, the detail-form displays perfectly. However, after clicking on the datatable paging to go to the next page (next record of datatable), the detail-form does not show up. I attempted to change the datatables c ...

Display alternate text within a div element that shares the same class using JQuery

Is there a way to display the alt text of my images on divs with the same class? Currently, my code only shows the alt of the first image on all divs. Can someone help me? This is what I have: <div id="tela"> <div class="folha"><img sr ...

Issues persist with the functionality of JQuery's .on() command

I am trying to set up things very simply, but for some reason I can't figure out why it's not working. Even though I believe everything is correct, it just doesn't work. .navigate-button is being loaded into .overlay-content using Ajax, whi ...

Perform a series of sequential HTTP requests using the got.js library and Promise objects

Looking to use the got library for making http requests while correctly implementing Promises. Despite my efforts to use Promises in my code, they never seem to work as expected. Take a look at this pseudo-code snippet: function obtainToken() { var ...

Creating hyperlinks in HTML using a similar functionality to a LinkButton within a Repeater control in ASP.NET

I have a project where a list of questions is pulled from a database. These questions are asked to people who then vote on them. When I select a question, I want to display the votes on a chart along with the question itself. I don't want to use a rep ...

Obtain the closest numerical range using JavaScript

I have a range object and an array of price values. My goal is to find the nearest range from the range object for each value in the price values array. I attempted the solution below, but it did not give me the correct range. range = { 0: '25-500 ...

Getting the value from input text using an AJAX POST request

Display: <div class="form-group"> <label for="regular" class="col-sm-2 control-label">Search</label> <div class="col-sm-10"> <select class="form-control" id="search" name="search" required> <op ...

Ways to stimulate a right-click event on an htmlelement in Angular 2

Is it possible to achieve the same functionality in Angular 2 as triggering a right-click event in jQuery? For example: ('#element').trigger({ type: 'mousedown', which: 3 }); This is similar to how you can trigger a click event like ...

Adjust Anchor ID for Media Query Activation

I need help with changing the ID of an anchor tag when a media query is triggered. Here is the code I am currently attempting, but it's not working: $(window).resize(function() { if ($('.container').css('width') == "100%"){ ...

Tips for inserting HTML code within session statements

When a user signs in, I want to display this content. However, when I try to include the code within the echo statement, it doesn't work. How can I achieve this? <?php if(isset($_SESSION['userID'])){ echo 'PLACE CODE HERE'; } ? ...

use bootstrap to align text vertically according to the image

I am trying to figure out how to center a text vertically next to an image. While I know how to align text horizontally using text-center in bootstrap, I am unsure about how to align it vertically. Is there a way to accomplish this using bootstrap? < ...

As the page is resized or zoomed in and out, the div elements start shifting in different directions

When I apply position:absolute to prevent the elements from moving when zooming in and out of the page, they all end up congregating in one place. Can anyone help me with this issue? None of the solutions I've found have worked so far. I'm develo ...