Integrate a loading screen on the website

Check out the awesome animation I created! Can this be used as a preloader on my website? Should I stick to creating a simple .gif or opt for a CSS animation instead? If it’s feasible, how do I go about integrating it into my site? Most tutorials suggest adding the CSS class to the body tag, but I’m facing a unique challenge.

// JavaScript code snippet 
var bar = $('span');
var p = $('.noumero');

var width = bar.attr('style');
width = width.replace("width:", "");
width = width.substr(0, width.length-1);

var interval;
var start = 0; 
var end = parseInt(width);
var current = start;

var countUp = function() {
  current++;
 p.html(current);

 if (current === end) {
  clearInterval(interval);
 }
 };

 interval = setInterval(countUp, (2000 / (end + 1)));
// CSS Code Snippet

div.meter {
 position: relative;
 width: 400px;
 height: 4px;
 margin-top: 50px;
}

/* More CSS styles here */

@keyframes grower {
  0% {
    width: 0%;
   }
  }

/* More keyframes and animations here */ 

</script>
<div class="meter">
  <p class="theR">R</p>  
  <span style="width:255px;" class="theline"></span>
   <p class="noumero the255"></p>  
</div>
<div style="clear:both"></div>

Answer №1

To hide the content of a document, you can use display:none in CSS. Additionally, employ $.holdReady() to pause .ready() handlers, and utilize .fadeToggle() to create a fading effect on the .meter element upon completing an animation, followed by revealing the content of the document once the fade-in effect of the .meter container finishes.

$.holdReady(true);

var bar = $('span');
var p = $('.noumero');

var width = bar.attr('style');
width = width.replace("width:", "");
width = width.substr(0, width.length - 1);

var interval;
var start = 0;
var end = parseInt(width);
var current = start;

var countUp = function() {
  current++;
  p.html(current);

  if (current === end) {
    clearInterval(interval);
    $(".meter").fadeToggle(500, function() {
      $.holdReady(false);
    })
  }
};

interval = setInterval(countUp, (2000 / (end + 1)));

$(document).ready(function() {
  $(".content").fadeToggle(5000)
})
div.meter {
  position: relative;
  width: 400px;
  height: 4px;
  margin-top: 50px;
}
div.meter span {
  display: block;
  height: 100%;
  animation: grower 1.8s linear;
  -moz-animation: grower 1.8s linear;
  -webkit-animation: grower 1.8s linear;
  -o-animation: grower 1.8s linear;
  position: relative;
  top: -1px;
  left: -1px;
  background-color: rgba(255, 0, 0, 1);
  -webkit-background-size: 45px 45px;
  -moz-background-size: 45px 45px;
  -o-background-size: 45px 45px;
  background-size: 45px 45px;
}
.theR {
  float: left;
  font-size: 24px;
  font-weight: bold;
  color: rgba(255, 0, 0, 1);
  float: left;
  display: block;
  margin-top: 0px;
  font-family: 'Montserrat', sans-serif;
}
.the255 {
  float: left;
  font-size: 24px;
  font-weight: bold;
  color: rgba(255, 0, 0, 1);
  float: left;
  display: block;
  margin-top: 0px;
  font-family: 'Montserrat', sans-serif;
}
.theline {
  width: 255px;
  float: left;
  font-size: 24px;
  font-weight: bold;
  color: red;
  float: left;
  display: block;
}
@keyframes grower {
  0% {
    width: 0%;
  }
}
@-moz-keyframes grower {
  0% {
    width: 0%;
  }
}
@-webkit-keyframes grower {
  0% {
    width: 0%;
  }
}
@-o-keyframes grower {
  0% {
    width: 0%;
  }
}

.content {
  display:none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="meter">
  <p class="theR">R</p>
  <span style="width:255px;" class="theline"></span>
  <p class="noumero the255"></p>
</div>
<div style="clear:both"></div>
<div class="content">
Unique text that replaces Lorem ipsum, conveying a different message or information.
This new content is meant to be distinct and interesting, providing value and engaging the readers with fresh ideas and perspectives.
Feel free to be creative and express your thoughts uniquely.
</div>

Answer №2

One effective method that comes to mind is utilizing a spinner, similar to those available on the FontAwesome website. However, if you prefer to incorporate your own custom animation as a preloader, you will need to implement a separate function to monitor the progress of your loading process. If there is improvement detected, you can then execute the countup function:

interval = setInterval(checkLoading, (2000 / (end + 1)));

Within the checkLoading function, a basic mathematical formula can be used to accurately track the progress:

function checkLoading(){
   var elementLoaded=countElements();
   var realState = (elementLoaded/allElementsToLoad)*end;
   while (realState<curent){
       countUp();
   }
}

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

New Vuetify component for customizing data iterators with specific key names

Can I customize the key names in the Vuetify v-data-iterator component? https://i.sstatic.net/Znv41.jpg I need to change the header names without altering the property names inside the "items" array. How can I achieve this when dealing with special chara ...

What methods are available for modifying nodes generated dynamically?

I have been on a quest for quite some time now to find a way to manipulate HTML content that has been dynamically added. Initially, I fetch a cross-domain website using getJSON: $.getJSON('http://whateverorigin.org/get?url=' + encodeURIComponent ...

The Final Div Fluttering in the Midst of a jQuery Hover Effect

Check out my code snippet here: http://jsfiddle.net/ZspZT/ The issue I'm facing is that the fourth div block in my example is flickering quite noticeably, especially when hovering over it. The problem also occurs occasionally with the other divs. Ap ...

The initialized Javascript array solely consists of undefined elements, without any of the expected values

I was under the impression that I knew how to declare JavaScript arrays, but in this particular script, I seem to be stuck in an infinite loop of undefined elements within the array. In my code, I define three arrays containing numbers—two with multiple ...

Transforming React drag and drop page builder state into a functional html, css, and js layout

Currently, I am in the process of developing a drag and drop UI builder for react-based app frameworks. Before incorporating drag and drop functionality, my main focus is on rendering a page layout based on a structured array stored in the state. https:// ...

Experiencing problems with web page layout when using bootstrap on IE8?

Here is a code snippet that functions correctly in IE9 and later versions, but encounters issues in IE8: <div class="col-lg-5 col-md-5 col-sm-6 col-xs-6" id="div1"> <div class="panel panel-default" style="" id="panel1"> ...

Modify the appearance of a nested div using CSS hover on the main JSX container

Within the material-ui table component, I am dynamically mapping rows and columns. The className is set to clickableRow. The TableRow also includes a hover options div on the right side: const generateTableHoverOptions = () => { if (selected) { ...

Ways to verify if information is being added to a JSON file or not

JSON Here is the JSON structure where I am adding data with a button click event. var myData = { "info" : [] }; JavaScript Function I have written this function to add data to the JSON object: myData.info.push({ "Name" :name, ...

The React forwardRef Higher Order Component is failing to provide a reference to the container element

I'm currently working on creating a higher order component (HOC) for closing an element when clicked outside of its space, known as a generic close on outside solution. In my understanding, this can be achieved using forwardRef and HOC implementation ...

How can I make the scrollbar invisible in the sticky header of a Material UI Table?

In my React project, I have implemented a Material-UI Table with a fixed header. The issue I am facing is that the scrollbar in the table header overlaps it and I want to hide it while still displaying it in the body of the table. I have attempted to modi ...

Resetting CSS animations using animation-delay

My aim is to animate a series of images on my landing page using Next.js and SCSS. The issue arises when I try to add dynamic animations that reset after each cycle. The delay in the animation causes the reset to also be delayed, which disrupts the flow. I ...

What is the best way to align list items both to the right and left in my navigation

How can I justify list items both right and left in my navigation bar? <nav class="navbar navbar-expand-lg navbar-light bg-light"> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" ...

Changing the Default Title Presentation in Magnific Popup Using Custom HTML Elements

When utilizing Magnific Popup to generate an image gallery with customized titles containing HTML content, I am facing a challenge. The popup consistently displays the default title attribute value instead of my specified custom title, despite attempts to ...

Using Vue to iterate through a list with conditional logic is as intuitive

I am completely new to vue, and facing a challenge with a conditional situation that I usually handle with PHP. My goal is to iterate through an element with a condition inside it. Below is how I envision the structure: <ul> <li>A</li&g ...

Remove inline CSS from HTML elements

Having a large HTML file structured like this: <div style="min-height: 32px; padding: 5px; width: 800px; margin: 50px auto; overflow: auto; font-size: 12px;" class="selectable clearfix selected_layer" id="wrap"> <div class="selectable" id="l1" st ...

Transitioning CSS on the removal of a class

I'm attempting to implement a sliding effect on a div using CSS transitions, but it seems that the transition only works when closing the div. HTML: <div class="slider closed" id="more-details"> Some content </div> CSS: .slider ...

Turn off hover opacity effect for a specific image

Currently, I've implemented a hover opacity effect on my images using the following CSS: img { opacity: 1.0; filter: alpha(opacity=1.0); } img:hover { opacity: 0.6; filter: alpha(opacity=0.6); } However, I now have a specific image for whi ...

JavaScript/CSS memory matching game

Just starting out in the world of programming and attempting to create a memory game. I've designed 5 unique flags using CSS that I want to use in my game, but I'm feeling a bit stuck with where to go next. I understand that I need some function ...

Converting & Modifying a PHP array variable into JavaScript

I've been experimenting with a fresh method for users to input data into an HTML form using the Slim Select JavaScript library. So far, I've got the basic functionality down, including a preset list of <option> items. Previously, the PHP ...

Animate your menu on hover with jQuery!

I am experiencing an issue with centering the background image below a link. When using mouseleave, the image does not return exactly to the center of the list. Any assistance on how to resolve this would be greatly appreciated. Thank you! Here is the ref ...