How to correctly have a smooth preloader fade out

ali haras

I am using this script I found on the internet, but the fadeout is not working. I want a smooth fadeout.

var loader = document.getElementById('spinner');
window.addEventListener("load", function() {
  //Hide the spinner after 2 seconds
  setTimeout(function() {
    loader.style.display = 'none';
  }, 2000);
});

$("#spinner").fadeOut();
<section id="spinner">
  <div id="preloader">Loading...</div>
</section>

Rory McCrossan

To do what you require you need to include a reference to the jQuery.js script in the page, and you also need to call the fadeOut() line in the handler for the setTimeout(), so that it runs when the 2 seconds have elapsed. Try this:

window.addEventListener("load", function() {
  setTimeout(function() {
    $("#spinner").fadeOut();
  }, 2000);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<section id="spinner">
  <div id="preloader">Loading...</div>
</section>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to increase the fade out time of a Preloader?

Fade in and out image with preloader

How to smooth fade in-out for toggle text using button click?

How to have fade in and fade out between multi widgets

AngularJS ngAnimate ngView smooth fade out/in animation

Making a smooth fade out for imageview in android

Hover over div/image to fade out image and have text fade in, but hovering over text removes fade out of image. How to prevent?

how to achieve *SMOOTH* fade in and out animation on mobile with jquery and css3?

How to have an element fade out and another element fade in in its place on window load?

How to fade text in, then out

How do I use fade-in/ease-in-out/or any animation to smooth out the revealing of my HTML, CSS and JS navigation menu?

How to apply a smooth fade in delay effect

How to fade in and fade out text in loop

CSS how to make an element fade in and then fade out?

How to set Fade in or Fade out on <a-sky>

How to fade-out and fade-in in React?

How to fade out and fade in paragraph in jQuery?

How to make a 50% fade in and a 100% fade out?

How can I make my loader fade out and display my website correctly?

How to fade out parent element?

How to fade out an item in canvas

How to fade in and out an ActivityIndicator in Swift?

How to fade a UIVisualEffectView and/or UIBlurEffect in and out?

How to fade out a NSView with animation?

How to fade in and out color of svg

React - how to wait and fade out?

How to fade in and out a text in Pygame

How to create a fade out button

How to make text fade out