How to set animation in css3? How to set simple animation in css
How to set animation in css3? What this article brings to you is to introduce how to set simple animations in CSS3. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
First of all, let’s take a look at the attributes needed to implement simple animations in CSS3: animation attributes, @keyframes “rules”.
animation attribute and @keyframes "Rule" is a new attribute of CSS3. The animation attribute can be used to set many CSS styles for animation, such as color, background-color, height, or width. [Recommended video learning: css3 tutorial, learn more about css3 properties]
We first define @keyframes "rules" and then call them in the animation attribute to achieve a simple animation. It worked.
As shown below: To achieve continuous switching of background color
.element { animation: pulse 5s infinite; } @keyframes pulse { 0% { background-color: #001F3F; } 100% { background-color: #FF4136; } }
After running, the background color will continue to change, from the #001F3F color value to the #FF4136 color value transitional change, and in between Some transitional background colors will be displayed. You can try it yourself.
Each @keyframes rule defines what should happen at a specific moment during the animation. For example, 0% is the beginning of the animation and 100% is the end. These keyframes can then be controlled via the shorthand animation property or its eight sub-properties to give greater control over how these keyframes should be manipulated.
Let’s take a look at the sub-properties of the animation property? what's the effect?
1. animation-name: declares the name of the at-rule to be operated by @keyframes.
2. animation-duration: The length of time required for the animation to complete a cycle.
3. animation-timing-function: Create a preset acceleration curve, such as ease or linear.
4. animation-delay: The time between the element being loaded and the start of the animation sequence.
5. animation-direction: Set the direction of animation after looping. Its default value is reset every cycle.
6. animation-iteration-count: The number of times the animation should be executed.
7. animation-fill-mode: Set the value applied before/after animation.
For example, we can set the last state of the animation to stay on the screen, or we can set it to switch back before the animation starts.
8. animation-play-state: pause/play animation.
The sub-properties can then be used like this:
@keyframes stretch { /* 在这里声明动画的动作 */ } .element { animation-name: stretch; animation-duration: 1.5s; animation-timing-function: ease-out; animation-delay: 0s; animation-direction: alternate; animation-iteration-count: infinite; animation-fill-mode: none; animation-play-state: running; } /* 相同: */ .element { animation: stretch 1.5s ease-out 0s alternate infinite none running; }
Here is the complete list of what each sub-property can take:
Multiple Steps
It is useful to comma separate the 0% and 100% values inside @keyframes if the animation has the same start and end properties @keyframes:
@keyframes pulse { 0%, 100% { background-color: yellow; } 50% { background-color: red; } }
Multiple animations
We can declare multiple animations on the selector by separating values with commas. In the example below, we want to change the color of the circle with @keyframe while also nudging it from side to side in the other direction.
.element { animation: pulse 3s ease infinite alternate, nudge 5s linear infinite alternate; }
When we set animation, in order to make the animation effect more natural and achieve more effects, it can be used in conjunction with other properties of CSS3. For example:
1. transform: translate()
2. transform: scale()
3. transform: rotate()
4. Opacity
Compatibility of css3 animation
We hope to be compatible with as many old browsers as possible, we need to use some prefixes:
.element { -webkit-animation: KEYFRAME-NAME 5s infinite; -moz-animation: KEYFRAME-NAME 5s infinite; -o-animation: KEYFRAME-NAME 5s infinite; animation: KEYFRAME-NAME 5s infinite; } @-webkit-keyframes KEYFRAME-NAME { 0% { opacity: 0; } 100% { opacity: 1; } } @-moz-keyframes KEYFRAME-NAME { 0% { opacity: 0; } 100% { opacity: 1; } } @-o-keyframes KEYFRAME-NAME { 0% { opacity: 0; } 100% { opacity: 1; } } @keyframes KEYFRAME-NAME { 0% { opacity: 0; } 100% { opacity: 1; } }
Summary: The above is the entire content of this article. You can try it yourself, check the effect, and deepen your understanding. I hope it will be helpful to your study.
The above is the detailed content of How to set animation in css3? How to set simple animation in css. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



When Microsoft launched Windows 11, it brought a lot of changes. One of the changes is an increase in the number of user interface animations. Some users want to change the way things appear, and they have to find a way to do it. Having animations makes it feel better and more user-friendly. Animation uses visual effects to make the computer look more attractive and responsive. Some of them include sliding menus after a few seconds or minutes. There are many animations on your computer that can affect PC performance, slow it down, and interfere with your work. In this case you have to turn off animation. This article will introduce several ways that users can improve the speed of their animations on PC. You can apply the changes using Registry Editor or a custom file you run. How to improve animations in Windows 11

CSS animation: How to achieve the flash effect of elements, specific code examples are needed. In web design, animation effects can sometimes bring a good user experience to the page. The glitter effect is a common animation effect that can make elements more eye-catching. The following will introduce how to use CSS to achieve the flash effect of elements. 1. Basic implementation of flash First, we need to use the animation property of CSS to achieve the flash effect. The value of the animation attribute needs to specify the animation name, animation execution time, and animation delay time
![Animation not working in PowerPoint [Fixed]](https://img.php.cn/upload/article/000/887/227/170831232982910.jpg?x-oss-process=image/resize,m_fill,h_207,w_330)
Are you trying to create a presentation but can't add animation? If animations are not working in PowerPoint on your Windows PC, then this article will help you. This is a common problem that many people complain about. For example, animations may stop working during presentations in Microsoft Teams or during screen recordings. In this guide, we will explore various troubleshooting techniques to help you fix animations not working in PowerPoint on Windows. Why aren't my PowerPoint animations working? We have noticed that some possible reasons that may cause the animation in PowerPoint not working issue on Windows are as follows: Due to personal

We often use ppt in our daily work, so are you familiar with every operating function in ppt? For example: How to set animation effects in ppt, how to set switching effects, and what is the effect duration of each animation? Can each slide play automatically, enter and then exit the ppt animation, etc. In this issue, I will first share with you the specific steps of entering and then exiting the ppt animation. It is below. Friends, come and take a look. Look! 1. First, we open ppt on the computer, click outside the text box to select the text box (as shown in the red circle in the figure below). 2. Then, click [Animation] in the menu bar and select the [Erase] effect (as shown in the red circle in the figure). 3. Next, click [

How to use Vue to implement typewriter animation special effects Typewriter animation is a common and eye-catching special effect that is often used in website titles, slogans and other text displays. In Vue, we can achieve typewriter animation effects by using Vue custom instructions. This article will introduce in detail how to use Vue to achieve this special effect and provide specific code examples. Step 1: Create a Vue project First, we need to create a Vue project. You can use VueCLI to quickly create a new Vue project, or manually

This website reported on January 26 that the domestic 3D animated film "Er Lang Shen: The Deep Sea Dragon" released a set of latest stills and officially announced that it will be released on July 13. It is understood that "Er Lang Shen: The Deep Sea Dragon" is produced by Mihuxing (Beijing) Animation Co., Ltd., Horgos Zhonghe Qiancheng Film Co., Ltd., Zhejiang Hengdian Film Co., Ltd., Zhejiang Gongying Film Co., Ltd., Chengdu The animated film produced by Tianhuo Technology Co., Ltd. and Huawen Image (Beijing) Film Co., Ltd. and directed by Wang Jun was originally scheduled to be released in mainland China on July 22, 2022. Synopsis of the plot of this site: After the Battle of the Conferred Gods, Jiang Ziya took the "Conferred Gods List" to divide the gods, and then the Conferred Gods List was sealed by the Heavenly Court under the deep sea of Kyushu Secret Realm. In fact, in addition to conferring divine positions, there are also many powerful evil spirits sealed in the Conferred Gods List.

Microsoft Windows 11 includes many new features and functions. The user interface has been updated and the company has also introduced some new effects. By default, animation effects are applied to controls and other objects. Should I disable these animations? Although Windows 11 features visually appealing animations and fade effects, they can cause your computer to feel sluggish to some users as they add a bit of lag to certain tasks. It's easy to turn off animations for a more responsive user experience. After we see what other changes have been made to the operating system, we'll walk you through how to turn animation effects on or off in Windows 11. We also have an article on how to

According to news from this site, Miyazaki Hayao's animated film "Porco Rosso" has announced that it will extend the release date to January 16, 2024. This site previously reported that "Porco Rosso" has been launched in the National Art Federation Special Line Cinema on November 17, with a cumulative box office of over 2,000 10,000, with a Douban score of 8.6, and 85.8% of 4 and 5 star reviews. "Porco Rosso" was produced by Studio Ghibli and directed by Hayao Miyazaki. Moriyama Moriyama, Tokiko Kato, Otsuka Akio, Okamura Akemi and others participated in the dubbing. It was originally released in Japan in 1992. The film is adapted from Hayao Miyazaki's comic book "The Age of Airships" and tells the story of the Italian Air Force's ace pilot Pollock Rosen who was magically turned into a pig. After that, he became a bounty hunter, fighting against air robbers and protecting those around him. Plot synopsis: Rosen is a soldier in World War I
