Tips on ending loading animation once the screen has finished loading

@import url(http://fonts.googleapis.com/css?family=Play:400,700);
* {
  box-sizing: border-box;
}

body {
  background-color: #222;
  font-family: "Play";
}

h1 {
  font-size: 2rem;
  color: #FFF;
  text-align: center;
  text-transform: uppercase;
}

.smart-glass {
  position: absolute;
  margin: auto;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  width: 288px;
  height: 388px;
}

.logo {
  width: 288px;
  height: 288px;
  position: relative;
}

.circle {
  padding: 20px;
  border: 6px solid transparent;
  border-top-color: #40A800;
  border-radius: 50%;
  width: 100%;
  height: 100%;
  animation: connect 2.5s linear infinite;
}

.xbox {
  background: #FFF;
  width: 80px;
  height: 80px;
  border-radius: 100%;
  overflow: hidden;
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  bottom: 0;
  margin: auto;
}
.xbox:after, .xbox:before {
  content: "";
  display: block;
  border-top: 10px solid #222;
  border-radius: 50%;
  height: 90%;
  width: 120%;
  transform: rotate(-45deg);
  position: absolute;
  right: -30%;
  top: 15%;
}
.xbox:before {
  left: -30%;
  transform: rotate(45deg);
}

.loading-text {
  text-transform: uppercase;
  color: #FFF;
  text-align: center;
  margin: 10px 0;
  font-size: 1.4rem;
}

@keyframes connect {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(-360deg);
  }
}
<div class="smart-glass">
  <h1>Xbox</h1>
  <div class="logo">
    <div class="circle">
      <div class="circle">
          <div class="circle">
          </div>
      </div>
  </div>
  <div class="hold-x">
    <div class="xbox"></div>
   </div>
  </div>
  <div class="loading-text">
    Loading...
  </div>
</div>

I came across this stylish loading animation on a website and I'm thinking of incorporating it into my project. However, my concern is how to pause or stop the animation once the page finishes loading. Any suggestions or guidance on this matter would be greatly appreciated.

Answer №1

One way to achieve this is:

$('.smart-glass').css('display','none');

In the code snippet above, I have set an interval for hiding the element after a certain period of time. You can use this piece of code when you want to hide the animation.

setInterval(function(){ $('.smart-glass').fadeOut(); 
$('body').css('background', 'transparent');

 }, 5000);
@import url(http://fonts.googleapis.com/css?family=Play:400,700);
* {
  box-sizing: border-box;
}

body {
  background-color: #222;
  font-family: "Play";
}

h1 {
  font-size: 2rem;
  color: #FFF;
  text-align: center;
  text-transform: uppercase;
}

.smart-glass {
  position: absolute;
  margin: auto;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  width: 288px;
  height: 388px;
}

.logo {
  width: 288px;
  height: 288px;
  position: relative;
}

.circle {
  padding: 20px;
  border: 6px solid transparent;
  border-top-color: #40A800;
  border-radius: 50%;
  width: 100%;
  height: 100%;
  animation: connect 2.5s linear infinite;
}

.xbox {
  background: #FFF;
  width: 80px;
  height: 80px;
  border-radius: 100%;
  overflow: hidden;
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  bottom: 0;
  margin: auto;
}
.xbox:after, .xbox:before {
  content: "";
  display: block;
  border-top: 10px solid #222;
  border-radius: 50%;
  height: 90%;
  width: 120%;
  transform: rotate(-45deg);
  position: absolute;
  right: -30%;
  top: 15%;
}
.xbox:before {
  left: -30%;
  transform: rotate(45deg);
}

.loading-text {
  text-transform: uppercase;
  color: #FFF;
  text-align: center;
  margin: 10px 0;
  font-size: 1.4rem;
}

@keyframes connect {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(-360deg);
  }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="smart-glass">
  <h1>Xbox</h1>
  <div class="logo">
    <div class="circle">
      <div class="circle">
          <div class="circle">
          </div>
      </div>
  </div>
  <div class="hold-x">
    <div class="xbox"></div>
   </div>
  </div>
  <div class="loading-text">
    Loading...
  </div>
</div>

Answer №2

Have you considered using an if statement in this situation? It appears to be a perfect fit for the scenario at hand. After searching for a simple and effective solution, I decided to place the loader inside the if statement as shown below. This approach worked well for my PHP code.

<?php
if (!isset($_SESSION['something'])) {
    ?>
    <div>
        <div>
            <div class='loader'></div>
            <br>
            <div> Redirecting...</div>
        </div>
    </div>
    <?php
    echo '<meta http-equiv=REFRESH CONTENT=3;url=url>';
} else {
    ?>

Answer №3

To start, consider using the fadeOut method on the animated section and then proceed to remove its content from the DOM.

 $(".smart-glass").fadeOut(2500,function(){  // Fading out over 2.5 seconds
  $(".smart-glass").remove();   // Removing the animated portion from the DOM
  $('body').css('background-color',"#ffffff"); // Changing background color to white
 })
})

PLUNKER

Answer №4

To halt the animation upon loading the page, implement this custom jQuery script:

$(window).on('load', function() {
    $('.smart-glass').fadeOut(3000);
});

This unique JQuery method smoothly transitions the opacity of an element from 1 to 0, eventually setting display: none within a 3-second duration (3000 milliseconds). As a result, once it disappears, the element becomes invisible and the page functions as usual. Feel free to apply this technique to various elements such as inputs and forms without any disruption.

I trust that you will find this information beneficial.

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

Updating information on <element>

Having trouble with the <object> element. I'm trying to display different external pages, but it's not functioning properly. It seems like once I set the data for the first time, any subsequent changes have no effect. Do I need to refresh i ...

Google/StackExchange Menu Tab

I am interested in creating a navigation bar similar to Google's or StackExchange's new one, where it is always positioned at the top. It does not need to be fixed there, but I would like it to have links only. How can I achieve this layout with ...

MySQL automatically inserts a null record if no value is provided

Currently, I am working on a project that involves inserting, viewing, and deleting records. Although everything functions smoothly, an issue persists where a null record is automatically added for some reason. The deletion feature works perfectly for othe ...

How come the data from the Firebase real-time database is only displaying in the console and not on the page when using Vue.js?

I am encountering an issue while trying to display a value stored in my Firebase Realtime Database using the {{ exams.name }} syntax in Vue. Although I can see the value when I console.log it, it does not render on the page. However, when I attempted the s ...

"Unraveling the Mystery: Leveraging jQuery to Unleash the

I'm working on a script that looks like this: $(document).on("click", ".passingID", function () { var ids = $(this).attr('data-id'); $("#idkl").val( ids ); $.ajax({ method: "POST", url: ...

Is it feasible to implement different themes besides 'light' and 'dark' in React Material UI?

Currently, I am developing a user interface (UI) using React in combination with Material UI (v5+). The documentation provides information on how to utilize the extendTheme function along with CssVarsProvider to incorporate MUI colors into CSS. It also men ...

Obtain the URL currently loaded in the browser, excluding any URLs retrieved using jQuery's $.get function

I am working with a controller named examples.php, which contains the following function: public function total_records_of_current_dataset(){ $url = base_url().uri_string(); $get_current_segment = $this->uri->segment(3); $count_all_rows ...

Using AngularJS API within a standalone function: Tips and tricks

I'm diving into the world of AngularJS and I want to make an HTTP GET request to a distant server without messing up my current view code. After some research, I discovered a way to execute a function right after the HTML is loaded by using a standalo ...

How to fetch a single document from a nested array using Mongoose

Currently, I am working on a MongoDB database using Mongoose in Node.js. The collection structure resembles the following: { cinema: 'xxx', account: 'yyy', media: { data: [{ id: 1, name: 'zzz& ...

Discover the nearest class and smoothly expand it with the slideDown function in jQuery

Hey there, I'm working on implementing a "View More" button on my page. The button will reveal another unordered list that currently has the class of "hidden-list". When the user clicks on "View More", I want it to slideToggle the hidden-list element ...

`Why won't Puppeteer let me pass a variable into a page URL parameter?`

Encountered an error message: Error: Protocol error (Page.navigate): Invalid parameters Failed to deserialize params.url - BINDINGS: mandatory field missing at position 49... The issue arises when trying to pass a variable into the page URL parameter as s ...

When NuxtImg is utilized, the image will rotate 90 degrees with Nuxt3 NuxtImg

Recently, I have encountered an issue when using NuxtImg where my images appear rotated by 90°. This problem specifically arises with vertical mobile images that are read from supabase and displayed. Interestingly, the images look fine before uploading th ...

Tips on aligning two bootstrap columns side by side

Having trouble aligning my two columns side by side. Despite my efforts, the second column (col-11) keeps appearing below col-1. The image inside col-1 should be on the far left with the other column right next to it. <div class="container col-md-12 wm ...

What is the process for monitoring all functions that will run upon completion of an ajax request?

Let's say I am dealing with an ajax call that is initiated by a page over which I have no control. This page makes the request, processes the response, and performs its own tasks. None of this page's code belongs to me. How can I determine whic ...

Repeated Type Declarations in TypeScript

Recently, I've come across an interesting challenge involving duplicated TypeScript type declarations. Let me explain: In my project A, the dependency tree includes: A->@angular/http:2.3.1 A->B->@angular/http:2.3.1 Both A and B are install ...

Guidance on redirecting and displaying the URL retrieved from an API response object in the browser using express and axios

Currently in the process of developing a payment gateway using the Paystack API along with Axios for managing HTTP requests. After thoroughly examining their API documentation and reviewing their Postman collection, I was able to grasp how to structure th ...

Running PHP using Node.js | Redirecting with the help of .htaccess

Currently, I am using a Node.js Server with the following configuration: app.use(express.static(__dirname + '/public')); However, I am facing an issue when trying to execute a php file using the XMLHttpRequest function like this: var xhttp = n ...

Enhance your Vue.js application by dynamically adding a class when a computed value

Just delving into the world of vue.js and I have a simple query. I've been following a tutorial but now I'd like to add my own touch to it :-P Whenever there is a change in my rank, I would like to include a CSS class for animating the label. Ho ...

The execution of 'observe' on 'MutationObserver' failed because parameter 1 is not the correct type of 'Node'. Ensure to use select2() instead

Attempting to implement select2 for dynamically loaded data via ajax, I am encountering the error mentioned above. What could be the issue? Below is the code snippet in question: $(document).on('change', '[name="country"]', fu ...

The button is effectively disabled for a few seconds as needed, but unfortunately, the form cannot be submitted again using that button

The button is disabled for a specific duration as required, but the form does not get submitted through that button again. Below is the script code written in the head tag $(document).ready(function () { $('.myform').on('submit', ...