how to stop loading animation once the screen is loaded

Viewed 2128

@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>

Well i saw this loading animation on one website and i am planning to insert it into my code but the problem i am having is that how do i stop the animation once the page has completed loading. Any help would be highly appreciated

4 Answers

Why not using an if statement for this purpose? It seems to fit this scenario perfectly. I was looking for the same thing and could not find anything easy and really works, so I simply put the loader inside the if statement as below. Works 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 {
    ?>

If you want the animation to stop on the load of the page, use this JQuery code:

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

This is a JQuery function that makes the opacity go from 1 to 0, and then display: none in 3 seconds (3000 milliseconds). Therefore, after it reaches display: none, you can't see it, and the page goes on as normal. You can use inputs, and forms as well, and it won't be affected.

I hope this helps much.

Related