What is causing the animate callback to not properly wait for the completion of the animations?

Both animations are triggered simultaneously (sometimes even multiple times)....

<div id="home-bt" class="button"></div>
<div id="about-bt" class="button"></div>
<div id="beauty-bt" class="button"></div>
<div id="pamper-bt" class="button"></div>
<div id="gallery-bt" class="button"></div>
<div id="news-bt" class="button"></div>
<div id="contact-bt" class="button"></div>
</div>

</div>
<div class="page-container" id="home">
home

</div>
<div class="page-container" id="about">
about

</div> etc...
$(document).ready(function() {
  $(".page-container").hide();


 $("#home-bt").click(function() {
$(".page-container").hide(2000, function(){
    $("#home").show("slow");
  });  }); etc.....

I've also attempted the same approach with similar outcome...

$(document).ready(function() {
  $(".page-container").hide();


 $("#home-bt").click(function() {
$("#about,#beauty,#pamper,#gallery,#contact,#news").hide(2000, function(){
    $("#home").show("slow");
  });  });

Answer №1

If you want it to function smoothly, follow this example:

  let timer = setInterval(function () {
                            if (!$('#something').is(":animated")) {
                                clearInterval(timer);
                                $('#animateafterwait').show("fade", {}, 1000);
                            }
                        }, 300);

Answer №2

By utilizing the .page-container initially hidden with the addition of $(".page-container").hide();

Upon clicking the selector once followed by a second click, it will then wait for the specified time to reveal itself.

Check out the fiddle here

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

Error: The function 'fetch' is not recognized in Selenium Console

Having some trouble with Selenium and Chrome Developer Tools. I want to open Selenium, go to a URL, and then use driver.execute_script to make a fetch request via Console in Chrome Developer Tools within the Selenium window. However, when I try to run thi ...

jQuery Data Tables display the message "No data available in table" even when there is data present and visible on the table

After spending countless hours searching for a solution to my problem, I came across two potential fixes: one addressing "No Data Available in Table" for jQuery DataTables found here, and another dealing with the issue of data not displaying properly durin ...

What is the process for converting a multidimensional array from PHP into JavaScript?

Recently, I've been experimenting with dygraph. To populate my graph, I fetch data via an ajax call and then need to convert the returned JSON array into a JavaScript array. My dygraph options are set up like this: series = { sample1: { ...

Enhancing Graphics with Anti Aliasing in Three.js and WebGL

While spinning my model with an orbiter, I am experiencing some issues with anti-aliasing. Currently, I am using the following renderer: renderer = new THREE.WebGLRenderer({ preserveDrawingBuffer: true, antialias: true }) ...

Guide on sending a sizable item as a string utilizing Axios

In order to efficiently save a large and complex object as a JSON file on the server without needing to map it to an object in C# first, I am facing some challenges. Sometimes, when posting the object as a string, the data gets corrupted leading to errors ...

What is the process for adding a search box to Google Earth through the web browser?

Hey there, I am currently working on a project involving Google Earth. However, I'm facing an issue in the web view where there is no search box available to locate specific places in Google Earth. Could someone kindly guide me on how to implement a s ...

Is JavaScript still running despite not displaying insecure items due to IE 8 security warning?

After a user completes a transaction on my site, the confirmation page displays Google conversion tracking code in a small JavaScript snippet. This code is located on my Wordpay callback page, which pulls data from the regular site (HTTP) to the Worldpay s ...

Is Cognito redirect causing issues with Angular router responsiveness?

When employing social login via AWS Cognito, Cognito sends a redirect to the browser directing it to the signin redirect URL after signing in. In this case, the specified URL is http://localhost:4200/home/. Upon receiving this redirect, the application in ...

What is the method to ensure background images are loaded with SSL from a different domain?

I run an online store and to improve performance, the images are hosted on a different domain. However, when I switch to secure mode using SSL on certain parts of the website, the background images disappear. Trying to view the image directly in the browse ...

Prevent the ajax script from running if the previous call has not yet completed successfully

My situation involves a button that triggers an ajax function. Sometimes the server response is slow, causing users to click the button multiple times in frustration. The main ajax function in question is structured as follows: $.ajax({ type: "POS ...

Eliminating undesired borders of table cells using CSS

I am facing a unique and puzzling issue. Here is the simple markup: <table> <thead> <tr><th>1</th><th>2</th><th>3</th></tr> </thead> <tbody> <tr>< ...

Create a design where the logo seems to be suspended from the navigation bar using bootstrap

My goal is to achieve a navigation bar similar to the one shown in this image: Using Bootstrap 3, the code below is what I have implemented for my navigation: <nav class="navbar navbar-default navbar-fixed-top"> <div class="container"> <di ...

What sets apart a space after the ampersand from no space in Material UI?

Could you clarify the difference between using a space after the ampersand compared to not having a space? For example: Why is there a space after the ampersand in & label.Mui-focused but no space in &.Mui-focused fieldset? const WhiteBorderTextF ...

Creating Positioning Magic with HTML Elements

Currently working on an ASP.NET web app that utilizes a Master, with just a GridView at the bottom and a DIV at the top for further development. The goal is to keep the top DIV or header fixed while scrolling, ensuring it remains in place at the top of th ...

Adaptable images - Adjusting image size for various screen dimensions

Currently, my website is built using the framework . I am looking for a solution to make images resize based on different screen sizes, such as iPhones. Can anyone suggest the simplest way to achieve this? I have done some research online but there are t ...

Creating random numbers in HTML using JavaScript

Currently, I am attempting to develop an HTML random number generator using JavaScript to produce a randomized number and then notify the user of the generated number. However, I consistently encounter an error when obtaining my number, which is different ...

Tips for aligning website content (including the body and navigation bar) at the center in rtd sphinx

Trying to create documentation with the Read the Docs theme for Sphinx documentation. Want to center the entire webpage, including both the body and left navigation bar so that as the window width increases, the margins on both sides increase equally. Righ ...

Vue does not consistently update HTML when the reference value changes

I am trying to showcase the readyState of a WebSocket connection by utilizing a Ref<number> property within an object and displaying the Ref in a template. The value of the Ref is modified during WebSocket open and close events. However, I am encount ...

Troubleshooting JavaScript within Embedded Resources

Looking for the most effective method of debugging JavaScript in Visual Studio when dealing with embedded resource files? Due to the fact that JavaScript is compiled into a library, setting breakpoints directly on the source file may not yield desired res ...

The interval becomes congested due to the execution of two simultaneous Ajax calls

I have an Interval set to run a function every 3 seconds. intervalStepper = window.setInterval('intervalTick()','3000'); function intervalTick() { if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari ...