search
HomeWeb Front-endCSS TutorialCSS 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 loadingcss animation effectProduction 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);
  }
}

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;
}

2. Flash animation

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

@keyframes blink {
  50% {
    opacity: 0.5;
  }
}

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;
}

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);
  }
}

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;
}

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;
  }
}

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;
}

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
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
What is CSS Grid?What is CSS Grid?Apr 30, 2025 pm 03:21 PM

CSS Grid is a powerful tool for creating complex, responsive web layouts. It simplifies design, improves accessibility, and offers more control than older methods.

What is CSS flexbox?What is CSS flexbox?Apr 30, 2025 pm 03:20 PM

Article discusses CSS Flexbox, a layout method for efficient alignment and distribution of space in responsive designs. It explains Flexbox usage, compares it with CSS Grid, and details browser support.

How can we make our website responsive using CSS?How can we make our website responsive using CSS?Apr 30, 2025 pm 03:19 PM

The article discusses techniques for creating responsive websites using CSS, including viewport meta tags, flexible grids, fluid media, media queries, and relative units. It also covers using CSS Grid and Flexbox together and recommends CSS framework

What does the CSS box-sizing property do?What does the CSS box-sizing property do?Apr 30, 2025 pm 03:18 PM

The article discusses the CSS box-sizing property, which controls how element dimensions are calculated. It explains values like content-box, border-box, and padding-box, and their impact on layout design and form alignment.

How can we animate using CSS?How can we animate using CSS?Apr 30, 2025 pm 03:17 PM

Article discusses creating animations using CSS, key properties, and combining with JavaScript. Main issue is browser compatibility.

Can we add 3D transformations to our project using CSS?Can we add 3D transformations to our project using CSS?Apr 30, 2025 pm 03:16 PM

Article discusses using CSS for 3D transformations, key properties, browser compatibility, and performance considerations for web projects.(Character count: 159)

How can we add gradients in CSS?How can we add gradients in CSS?Apr 30, 2025 pm 03:15 PM

The article discusses using CSS gradients (linear, radial, repeating) to enhance website visuals, adding depth, focus, and modern aesthetics.

What are pseudo-elements in CSS?What are pseudo-elements in CSS?Apr 30, 2025 pm 03:14 PM

Article discusses pseudo-elements in CSS, their use in enhancing HTML styling, and differences from pseudo-classes. Provides practical examples.

See all articles

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment