Home Web Front-end CSS Tutorial CSS web page loading animation: create various cool loading animation effects

CSS web page loading animation: create various cool loading animation effects

Nov 18, 2023 pm 02:28 PM
Web page loading css animation effect Production skills

CSS web page loading animation: create various cool loading animation effects

When users enter a web page, the most impatient thing is waiting for the page to load. In order to alleviate users' anxiety, many websites have begun to use CSS loading animations to make page loading more interesting. In this article, we will learn how to use CSS to create various cool loading animation effects, and provide specific code examples to help you implement it.

1. Basic animation

First let us create some basic loading animations. We can use the animation property in CSS to create a basic animation. The animation property has several sub-properties, as follows:

  • animation-name: Select the name of the keyframe rule to be applied.
  • animation-duration: Defines the duration of a cycle (in seconds or milliseconds).
  • animation-timing-function: Define a cycle speed curve.
  • animation-delay: Define the delay time of a cycle.
  • animation-iteration-count: Defines the number of times the animation should play.

Now, let’s look at a few different types of basic loading animations.

1. Rotation animation

In this loading animation, we use the following code to define a rotation keyframe:

@keyframes rotate {
  from {
    transform: rotate(0deg);
  }
  
  to {
    transform: rotate(360deg);
  }
}
Copy after login

The above code uses the @keyframes rule to define A keyframe named "rotate". In this keyframe, we use the transform attribute to define the rotation. In from and to, we define the degree of rotation, from 0 to 360 degrees.

Next, we need to specify this animation for our "loader" element:

.loader {
  animation-name: rotate;
  animation-duration: 1s;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
}
Copy after login

2. Flash animation

In this loading animation, we use the following code to Define a cyclic blinking keyframe:

@keyframes blink {
  50% {
    opacity: 0.5;
  }
}
Copy after login

The above code uses the @keyframes rule to define a keyframe named "blink". In this keyframe, we use the opacity property to define the transparency of the element. At 50%, we set it to 0.5, which will make it cycle between two states.

To apply this animation to our "loader" element, use the following code:

.loader {
  animation-name: blink;
  animation-duration: 1s;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
}
Copy after login

2. Advanced Animation

Now, we have learned how to Create a basic loading animation in , let's further explore how to create more advanced animations. Here are some cool loading animations and their code examples.

1. Wave animation

In this loading animation, we use the following code to define the key frame of a wave mode:

@keyframes wave {
  0% {
    transform: translateX(0) translateY(0);
  }
  
  50% {
    transform: translateX(30px) translateY(15px);
  }
  
  100% {
    transform: translateX(0) translateY(0);
  }
}
Copy after login

In the above code, we use transform Properties to create waveform effects. At 0% and 100% positions, we set the element to its initial position. At the 50% position, we use translateX (horizontal translation) and translateY (vertical translation) to create the waveform.

Next, we specify this animation for our "loader" element:

.loader {
  animation-name: wave;
  animation-duration: 1s;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
}
Copy after login

2. Diffusion animation

In this loading animation, we use the following code to define A diffusion keyframe:

@keyframes spread {
  0% {
    transform: scale(0);
    opacity: 0.5;
  }
  
  50% {
    transform: scale(1);
    opacity: 0.1;
  }
  
  100% {
    transform: scale(0);
    opacity: 0.5;
  }
}
Copy after login

In the above code, we use the transform attribute to create a diffusion effect. At 0% and 100% we set the element to its initial values ​​of minimization and transparency. At the 50% position, we use the scale property to create the diffusion animation.

Next, we specify this animation for our "loader" element:

.loader {
  animation-name: spread;
  animation-duration: 1s;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
}
Copy after login

Summary

By using CSS, we can create various types of loading animations for our website . These loading animations can make page loading more interesting and relieve users' waiting anxiety. In this article, we learned how to create some basic loading animations, as well as how to make more advanced animations. I hope these code examples are helpful in your work.

The above is the detailed content of CSS web page loading animation: create various cool loading animation effects. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Working With GraphQL Caching Working With GraphQL Caching Mar 19, 2025 am 09:36 AM

If you’ve recently started working with GraphQL, or reviewed its pros and cons, you’ve no doubt heard things like “GraphQL doesn’t support caching” or

Building an Ethereum app using Redwood.js and Fauna Building an Ethereum app using Redwood.js and Fauna Mar 28, 2025 am 09:18 AM

With the recent climb of Bitcoin’s price over 20k $USD, and to it recently breaking 30k, I thought it’s worth taking a deep dive back into creating Ethereum

Vue 3 Vue 3 Apr 02, 2025 pm 06:32 PM

It's out! Congrats to the Vue team for getting it done, I know it was a massive effort and a long time coming. All new docs, as well.

Can you get valid CSS property values from the browser? Can you get valid CSS property values from the browser? Apr 02, 2025 pm 06:17 PM

I had someone write in with this very legit question. Lea just blogged about how you can get valid CSS properties themselves from the browser. That's like this.

A bit on ci/cd A bit on ci/cd Apr 02, 2025 pm 06:21 PM

I'd say "website" fits better than "mobile app" but I like this framing from Max Lynch:

Comparing Browsers for Responsive Design Comparing Browsers for Responsive Design Apr 02, 2025 pm 06:25 PM

There are a number of these desktop apps where the goal is showing your site at different dimensions all at the same time. So you can, for example, be writing

Stacked Cards with Sticky Positioning and a Dash of Sass Stacked Cards with Sticky Positioning and a Dash of Sass Apr 03, 2025 am 10:30 AM

The other day, I spotted this particularly lovely bit from Corey Ginnivan’s website where a collection of cards stack on top of one another as you scroll.

Using Markdown and Localization in the WordPress Block Editor Using Markdown and Localization in the WordPress Block Editor Apr 02, 2025 am 04:27 AM

If we need to show documentation to the user directly in the WordPress editor, what is the best way to do it?

See all articles