How to create working website page loader

Feb. 28, 2024 by shrikant patel Posted in programming Category 0 Comments 53 Views

How to create working website page loader

Creating a website loader: A simple guide for beginners

When you visit a website and notice a cool animation or progress bar that appears while the site page is loading? That's called a website loader, and it's a great way to engage visitors while they wait for your content to load. In this guide, we'll learn how to create a basic website loader using HTML, CSS, and a touch of JavaScript. Don't worry if you're new to coding – we'll explain each step in simple terms.

 

What is a website loader?

A website loader is a visual element that appears on a webpage while the content is loading. It gives users a visual cue that lets them know the website is working on loading their requested page. This can be anything from a simple spinning animation to a progress bar that fills up as the page loads, images or website logo anything that shows the webpage is loading.

 

Step 1: Setting Up Your HTML


First, let's create the basic structure of our webpage. Open your favourite code editor (like Visual Studio Code, Sublime Text, or Notepad++) and create a new HTML file. You can name it index.html or whatever do you want here is a simple HTML template to get started:

 

<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>webpage loader</title>

<link rel="stylesheet" href="styles.css">
</head>

<body>

    <div class="loader-wrapper">
  <div class="loader"></div>
</div>

<div class="content">
        <h1>Welcome to My Website!</h1>
        <!-- Add more content here -->
    </div>

<script src="script.js"></script>

</body>
</html>

 

Step 2: Styling with CSS


Next, let's create the styles for our loader. Create a new file in the same directory as your index.html file and name it styles.css. This CSS file will define the appearance of our loader: 

 

.loader-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: #fff;
  z-index: 9999;
}

.loader {
  border: 4px solid #f3f3f3;
  border-top: 4px solid #3498db;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.content {
  display: none; /* Hide content initially */
}

 

In this CSS, we've created a simple spinning loader using CSS animations. The .loader-container centers the loader vertically and horizontally on the page, while .loader defines the appearance of the spinning animation.

Step 3: Adding JavaScript 


If you want to make your loader interactive or control its behavior based on the page's loading status, you can use JavaScript. Create a new file in the same directory called script.js. For this example, we'll just hide the loader once the page has fully loaded: 

 

window.addEventListener("load", function() {
  // Hide the loader
  document.querySelector('.loader-wrapper').style.display = 'none';
  // Show the content
  document.querySelector('.content').style.display = 'block';
});

 

Step 4: Testing Your Loader
Now that you've created your loader, it's time to see it in action! Open your index.html file in a web browser. You should see your loader spinning in the center of the page. After a few seconds, the loader will disappear, and your "Welcome to My Website!" message will be displayed.

 

Customizing Your Loader
Feel free to customize the loader to fit the style of your website. You can change the colors, size, animation speed, and more by adjusting the CSS properties in styles.css. Experiment with different designs until you find one that suits your website's look and feel.

 

Do you dream of turning your thoughts and words into income ? join us now and become blogger now.
PUBLICBLOGS.IN


programming website
If you went to earn online by just sharing your thoughts then join us now with Google and become blogger now.
PUBLICBLOGS.IN
Related Story
0 Comments

Leave a Comment