Issue with fadeOut and delay functions not behaving correctly

Having some trouble getting a div overlay to fade out when the page loads with a delay. For some reason, it's not fading and I can't figure out why...

    $("#loading").delay(3000).fadeOut(3000);
    #loading {
width:100%;
height:100%;
z-index:500;
background:#000;
position:absolute;
    }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div id="loading"></div>

Answer №1

If you need a delay in your code, consider using setTimeout()

setTimeout(function () { 
    $("#loading").fadeOut(3000);
}, 3000);

For more information, refer to the jQuery .delay() documentation:

The .delay() function is primarily used for adding delays between consecutive jQuery effects. Since it has limitations and does not allow for delay cancellation, it is recommended to use JavaScript's native setTimeout function for specific scenarios.

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

Is it feasible to adjust the Scrollbar's position?

Is there a way to change the position of a scrollbar on a webpage? Are there any alternative solutions for this issue? <div style="overflow: scroll; overflow-y: hidden"> </div> I am looking to relocate the scrollbar to a different componen ...

Unexpected result when trying to return a value from a recursive function

Attempting to solve the problem of calculating the number of ways a number can be decoded, with 1 as a, 3 as c, and 26 as z. The function seems to calculate the correct count, but for some reason only returns undefined. It appears that the recursive calls ...

What is the best way to implement a prev.next function in an image gallery using an array in JavaScript?

In the image gallery, you can simply click on each image to view a larger version. The enlarged image sources are pulled from the background-image of the smaller images. What I am aiming to achieve is the addition of previous and next buttons for easy navi ...

The results did not meet expectations when utilizing the incremental value within the loop

I need help finding a way to create a sequential counter for my nested loop. I attempted the following test: <template> <div class="container"> <ul> <li v-for="item in list" :key="item">{{ counter++ }}</li> &l ...

What could be causing the video to extend beyond the limits of the container?

When extending the result window, the video ends up overlapping the section below it. I am looking to keep the video within the confines of the section's height, which is set to height:100vh. Is there a way to accomplish this? Check out this jsFiddl ...

The universal CSS variables of Material UI

Creating reusable CSS variables for components can greatly simplify styling. In regular CSS, you would declare them like this: :root { --box-shadow: 0 2px 5px -1px rgba(0, 0, 0, 0.3); } This variable can then be utilized as shown below: .my-class { ...

Compile an ASP.NET website into static files such as HTML, CSS, and JavaScript prior to deployment

Can a simple ASP.NET website without ASP webform or .NET controls be precompiled into static files such as HTML, CSS, and JavaScript? I am interested in utilizing the master page feature and Visual Studio IDE intellisense while still being able to deploy ...

Update the date format in jQuery's datepicker

Currently, I am utilizing the jQuery datepicker in my project. I have connected a Textbox to the Datepicker. My goal is to adjust the date format to showcase dates in the following style: Tuesday, 29 - Jan - 2013. Could you please guide me on how to achi ...

Is there a way to dynamically change the source of an image based on different screen sizes using Tailwind CSS?

Currently, I am utilizing the next/Image component for setting an image and applying styling through tailwindcss. However, I have encountered a roadblock at this juncture. My Objective My goal is to dynamically change the src attribute of the image based ...

Are elements loaded and hidden by ng-hide and ng-show, or does loading only occur with ng-show?

Is this method of programming effective for handling large elements such as 10 mb images? Are there alternative solutions that would work better? ...

The function in PHP does not arbitrarily return a boolean value

After creating a template file for WordPress, I encountered an issue with a function that I wrote. Despite ensuring that the two variables are different (as I confirmed by printing them), the function consistently returns true. Even after testing and attem ...

Customize the default email validator in AngularJS

I am looking to customize the email validator in AngularJS by using a custom string for validating email addresses. However, when I tried implementing the code provided in the documentation, it doesn't seem to work as expected. Here is the code snippe ...

What is the best way to delay an observable from triggering the next event?

In my Angular project, I am implementing RxJs with two subjects. s1.next() s1.subscribe(() => { // perform some operation and then trigger the event for s2 s2.next() }); s2.subscribe(() => { // perform some operat ...

What is the best way to limit the length of a field in a datatable and provide an option to display the full data with "<more options>" at the end?

I am utilizing a datatable to showcase a report within my application. Some of the columns contain extensive data that I would like to truncate for viewing purposes, with the option to click and expand to see the entire content as needed. I attempted usin ...

Having trouble setting up the next-auth login page and experiencing issues with the getProviders() function

Greetings to all fellow web developers, I am currently working on a Next.js application that utilizes next-auth for user authentication. I have set up the [...nextauth].js file in the "pages/api/auth" directory and a signin.js file in the "pages/auth/" di ...

Using the variable obtained from a successful ajax call and inserting it into a jQuery selector

I'm encountering an issue with an ajax function that includes a success block. Within this block, I am attempting to remove an element. Here is the content of the success block: success:function(data, textStatus, jqXHR) { $("#comment +$data['p ...

Transforming canvas into blob with the help of cropper.js

After successfully creating an application with cropper.js to crop images, I encountered a challenge. Once the image is cropped, my goal was to send it as a blob to the server for storage. Referring to the documentation of cropper.js, it suggested using c ...

Feeling lost about arrow functions in JavaScript

Here is the code I am currently using to increment the value of intVariable using window.setInterval. var Arrow = (function () { function Arrow() { this.intVariable = 1; this.itemId = -1; this.interval = 25; } Arrow.p ...

Issue with ERR_HTTP_HEADERS_SENT persists despite implementation of return statements

When attempting to send a POST request to the server, an error is encountered: Error [ERR_HTTP_HEADERS_SENT]: Cannot modify headers after they are sent to the client at new NodeError (node:internal/errors:371:5) at ServerResponse.setHeader (node:_h ...

Tips for Utilizing the Accurate Google Map Code within Jquery Tabs

Looking for assistance in properly integrating Google maps into jQuery tabs. I am trying to incorporate two maps into the project. One map to display the location and another map to provide directions. Encountering an issue with the code, as Firebug rep ...