Creating a skeleton with JavaScript

Let's find out together how to create a loading effect on our elements during an AJAX call, for example!
•
Updated on August 14, 2026
•
2 min read
Believemy logo

Let’s discover together how to create a loading effect on our elements during an AJAX call, for example!

Image

 

Step 1

Let's start with our HTML code.

HTML
<div class="card">
  <div class="image">
    <img src="https://cdn.pixabay.com/photo/2021/01/21/16/17/english-cocker-spaniel-5937757_960_720.jpg" />
  </div>
  <div class="content">
    <h2>Animal Protection</h2>
    <p>Discover how to take action for animal protection.</p>
  </div>
</div>

<div class="card is-loading">
  <div class="image"></div>
  <div class="content">
    <h2></h2>
    <p></p>
  </div>
</div>

 

Step 2

For this example, we will use Flexbox on our body tag.

CSS
body {
  display: flex;
  align-items: center;
  justify-content: space-around;
  flex-wrap: wrap;
  height: 100vh;
}

 

Step 3

Now, let's take care of the cards.

CSS
.card {
  height: 379px;
  width: 300px;
  border-radius: 10px;
  transition: all 0.8s;
  overflow: hidden;
  background: black;
  box-shadow: 0 70px 63px -60px #000000;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

 

Step 4

So, we have our cards: let's integrate the white frame and its appearance on hover.

CSS
.border {
  height: 369px;
  width: 290px;
  border-radius: 10px;
  transition: all 1s;
  position: relative;
}

.border:hover {
    border: 1px solid white;
}

 

Step 5

We now have our cards and borders, but we only have black backgrounds... That's not very nice. Let's change that by adding photos to each card!

CSS
.card0 {
  background: url('https://i.pinimg.com/736x/8f/a0/51/8fa051251f5ac2d0b756027089fbffde--terry-o-neill-al-pacino.jpg') center center no-repeat;
  background-size: 300px;
}
    
.card0:hover {
    background: url('https://i.pinimg.com/736x/8f/a0/51/8fa051251f5ac2d0b756027089fbffde--terry-o-neill-al-pacino.jpg') left center no-repeat;
    background-size: 600px;
}

.card1 {
  background: url('https://i.pinimg.com/originals/28/d2/e6/28d2e684e7859a0dd17fbd0cea00f8a9.jpg') center center no-repeat;
  background-size: 300px;
}

.card1:hover {
    background: url('https://i.pinimg.com/originals/28/d2/e6/28d2e684e7859a0dd17fbd0cea00f8a9.jpg') left center no-repeat;
    background-size: 600px;
}

.card2 {
  background: url('https://i.pinimg.com/originals/ee/85/08/ee850842e68cfcf6e3943c048f45c6d1.jpg') center center no-repeat;
  background-size: 300px;
}

.card2:hover {
    background: url('https://i.pinimg.com/originals/ee/85/08/ee850842e68cfcf6e3943c048f45c6d1.jpg') left center no-repeat;
    background-size: 600px;
}

 

Step 6

Now, let's style our titles and icons.

CSS
.card h2 {
  font-family: Arial, sans-serif;
  color: white;
  margin: 20px;
  opacity: 0;
  transition: all 1s;
}

.fab {
  opacity: 0;
  transition: all 1s;
}

.icons {
  position: absolute;
  height: 130px;
  top: 226px;
  width: 50px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-around;
}

a {
  color: white;
}

 

Step 7

Now, let's make the icons and card titles appear on hover.

CSS
.card:hover h2 {
    opacity: 1;
}

.card:hover .fab {
    opacity: 1;
}

 

Bravo! We're done!

Share your result on the official Believemy discussion channel!

Category: Developers

Share this article

Want to help us? Share this article on your networks or even better: on your site, in an article or in your newsletter.

Believemy logo
Comments (0)

You need to be logged in to comment on this article: log in or sign up.

Read next

Create an image slideshow

Let's discover together how to create a simple and effective image slideshow using HTML, CSS and JavaScript!

December 6, 2024

Setting up a loader when changing a Nextjs page

Have you ever been on a site where you click on a link and nothing happens? Or perhaps you've wondered whether your request was actually received? This is where having a loader comes in. In this article, we'll explain why it's important to have a loader on your website, how to set it up in your Nextjs project and create a function that will display the loader until the page is loaded. If you want to improve the user experience on your website and reassure your visitors, this article is for you.

December 11, 2024

Creating an animated list with CSS

Let's find out how to create an animated hover list!

December 9, 2024

Creating animated presentation cards with JavaScript

Whether you're presenting the team behind your project or anything else, using animated presentation cards will give your page a successful finishing touch. Find out how in this article!

December 9, 2024

Display a number progressively on a counter with JavaScript

When we have numbers to display, we often present them blandly and without animation. And yet: creating an animation that progressively displays the final number is very easy to do and will enable you to liven up your numbers! Let's see how in this article.

December 11, 2024

Animate SVG illustrations with Lottie and JavaScript

Would you like to animate your illustrations without having images that are too heavy? Perhaps you'd even like to manage the speed? Then you've come to the right place! Find out how to animate SVG illustrations with Lottie!

December 9, 2024

Creating animated borders and rainbow blurs with CSS and JavaScript

Think again: it's not a shadow, it's a trick that will make your visitors think you've added borders and animated rainbow shadows! It's nothing of the sort: no borders or shadows are used in this tutorial. Let's discover the secret behind this trick.

December 9, 2024

Creating a clock using JavaScript

Imagine a clock that shows the time to your users, on a travel site for example, with the time zone of the destination country? Let's create this magnificent clock together, using JavaScript!

December 9, 2024

Become the solopreneur you dream of being.

First project, career change, business launch: access our courses, practice on real-world cases, and move forward with clear guidance.