current position:Home>On the new feature of CSS3: Animation
On the new feature of CSS3: Animation
2021-08-27 05:43:35 【Poached egg roll】
This is my participation 8 The fourth of the yuegengwen challenge 23 God , Check out the activity details :8 Yuegengwen challenge
@keyframes
@keyframes
( Keyframes ), Used to create animation , It controls by defining the style of keys in the animation sequence CSS Intermediate steps in the animation sequence . and transition
comparison ,@keyframes
You can control the intermediate steps of the animation sequence .
grammar :
@keyframes <keyframes-name> {
<keyframes-selector> {
<css-styles>
};
}
Copy code
<keyframes-name>
: Essential . Definition keyframes The name of .<keyframes-selector>
: Essential , Animation duration .from
, Equivalent to 0%.to
, Equivalent to 100%.<percentage>
, The point in time in the animation sequence that triggers the keyframe , Use percentages to express .
<css-styles>
:CSS attribute
@keyframes slidein {
from {
transform: translateX(0%);
}
to {
transform: translateX(100%);
}
}
Copy code
The start or end state of the animation is not specified
If a keyframe rule does not specify the start or end state of the animation ( That is to say ,0%/from
and 100%/to
, The browser will use the existing style of the element as the starting point / End state . This can be used to start element animation from the initial state , Finally return to the initial state .
Repeat the definition
-
Multiple keyframes use the same name , Subject to the last definition ( Cover the previous ).
/* Invalid */ @keyframes mymove { to { transform: translateX(50%); } } /* It works */ @keyframes mymove { to { transform: translateX(100%); } } Copy code
-
In a
@keyframes
Inside , The percentage of keyframes is duplicated , This is merged into one .@keyframes mymove { to { background-color: blue; } to { transform: translateX(100%); } } /* After the merger */ @keyframes mymove { to { background-color: blue; transform: translateX(100%); } } Copy code
-
In the same keyframe , The same attribute is repeatedly defined , The last defined attribute shall prevail ( Cover the previous ).
@keyframes identifier { 50% { top: 30px; /* Invalid */ left: 20px; } 50% { top: 10px; /* It works */ } } Copy code
In keyframes !important.
In keyframes !important Will be ignored .
@keyframes important1 {
from {
margin-top: 50px;
}
50% {
margin-top: 150px !important; /* Ignore */
}
to {
margin-top: 100px;
}
}
Copy code
CSSKeyframesRule
JavaScript Can pass CSSKeyframesRule
visit @keyframes
:
let myRules = document.styleSheets[0].cssRules;
let keyframes = myRules[0]; // a CSSKeyframesRule
Copy code
animation
@keyframes After creating the animation , Bind it to a selector , The animation will take effect .
animation
The attribute is animation-name
,animation-duration
,animation-timing-function
,animation-delay
,animation-iteration-count
,animation-direction
,animation-fill-mode
and animation-play-state
A shorthand form of attributes .
grammar :
animation: name duration timing-function delay iteration-count direction
fill-mode play-state;
Copy code
- The order of attribute values in each animation definition is important : It can be interpreted as
<time>
The first value of is assigned toanimation-duration
, The second one is assigned toanimation-delay
.
animation-name( It's necessary )
animation-name
, Specify the name of the animation , Each name represents a by @keyframes
Defined animation sequence .
grammar :
animation-name: keyframename|none;
Copy code
none
: No keyframes ( Disable animation ).keyframename
: Key frame name .
animation-duration( It's necessary )
animation-duration
, Specify the duration of an animation cycle , The default is 0s.
grammar :
animation-duration: time;
Copy code
time
: The length of an animation cycle , The unit is in seconds (s) Or milliseconds (ms), Invalid without unit value .
animation-timing-function
animation-timing-function
, Specify how the animation will complete a cycle ( Speed curve ). The default is "ease
". About timing-function You can refer to transition-timing-function part .
animation-delay
animation-delay
Property defines when the animation starts , The default is 0s.
Tips : Allow negative values ,-2s Make the animation start right away , But skip 2 Seconds into the animation .
grammar :
animation-delay: time;
Copy code
animation-iteration-count
animation-iteration-count
, Define how many times the animation should play , The default is 1 Time .
grammar :
animation-iteration-count: value;
Copy code
infinite
: Infinite loop animation .<number>
: The number of times the animation plays ; The default value is 1.- You can define cycles with decimals , To play part of the animation cycle : for example ,0.5 Play to half of the animation cycle .
- Don't be negative .
animation-direction
animation-direction
, Indicates whether the animation plays in reverse , The default is normal
.
normal
, The default value is . Play the animation as normal .reverse
, The animation plays in reverse , At the end of each cycle, the animation runs from the end to the end .alternate
, Animation turn back operation . in other words , Animation in odd times (1、3、5...) Forward play , In even numbers (2、4、6...) Reverse play .alternate-reverse
, Animation reverse turn back operation . in other words , Animation in odd times (1、3、5...) Reverse play , In even numbers (2、4、6...) Forward play .
animation-fill-mode
animation-fill-mode
, Set the state of the animation before and after execution ( The style applied to the element ).
-
none
: The default value is , No state of retention or processing . -
forwards
: Keep the calculated value of the last key frame during animation execution .The last keyframe depends on
animation-direction
andanimation-iteration-count
Value :animation-direction animation-iteration-count The last keyframe normal
/ 100% or to reverse
/ 0% or from alternate
even numbers 0% or from alternate
Odd number 100% or to alternate-reverse
even numbers 100% or to alternate-reverse
Odd number 0% or from -
backwards
: The first key frame of the animation , And inanimation-delay
Keep this value during .The first keyframe depends on
animation-direction
Value :animation-direction The first keyframe normal
oralternate
0% or from reverse
oralternate-reverse
100% or to -
both
: The animation will followforwards
andbackwards
The rules of , So we can extend the animation properties in two directions .
animation-play-state
animation-play-state
, Whether the animation is running or pausing . The default is running
.
grammar :
animation-play-state: paused|running;
Copy code
paused
: The current animation has stopped .running
: The current animation is running .
stay JS in , You can query it to determine whether the animation is running , You can also modify it to control the pause of animation . For example, control. .active
:
.animate {
animation-play-state: paused;
}
.active.animate {
animation-play-state: running;
}
Copy code
Resume a paused animation , When it will pause , Instead of starting at the beginning of the animation sequence .
Talking about CSS3 New characteristics
copyright notice
author[Poached egg roll],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2021/08/20210827054331470Z.html
The sidebar is recommended
- Crazy blessing! Tencent boss's "million JVM learning notes", real topic of Huawei Java interview 2020-2021
- JS JavaScript how to get the subscript of a value in the array
- How to implement injection in vuex source code?
- JQuery operation select (value, setting, selected)
- One line of code teaches you how to advertise on Tanabata Valentine's Day - Animation 3D photo album (music + text) HTML + CSS + JavaScript
- An article disassembles the pyramid architecture behind the gamefi outbreak
- BEM - a front-end CSS naming methodology
- [vue3] encapsulate custom global plug-ins
- Error using swiper plug-in in Vue
- Another ruthless character fell by 40000, which was "more beautiful" than Passat and maiteng, and didn't lose BMW
guess what you like
-
Huang Lei basks in Zhang Yixing's album, and the relationship between teachers and apprentices is no less than that in the past. Netizens envy Huang Lei
-
He was cheated by Wang Xiaofei and Li Chengxuan successively. Is an Yixuan a blessed daughter and not a blessed home?
-
Zhou Shen sang the theme song of the film "summer friends and sunny days" in mainland China. Netizen: endless aftertaste
-
Pink is Wangyuan online! Back to the peak! The new hairstyle is creamy and sassy
-
Front end interview daily 3 + 1 - day 858
-
Spring Webflux tutorial: how to build reactive web applications
-
[golang] walk into go language lesson 24 TCP high-level operation
-
August 23, 2021 Daily: less than three years after its establishment, Google dissolved the health department
-
The female doctor of Southeast University is no less beautiful than the female star. She has been married four times, and her personal experience has been controversial
-
There are many potential safety hazards in Chinese restaurant. The top of the program recording shed collapses, and the artist will fall down if he is careless
Random recommended
- Anti Mafia storm: He Yun's helpless son, Sun Xing, is destined to be caught by his dry son
- Introduction to flex flexible layout in CSS -- learning notes
- CSS learning notes - Flex layout (Ruan Yifeng tutorial summary)
- Today, let's talk about the arrow function of ES6
- Some thoughts on small program development
- Talk about mobile terminal adaptation
- Unwilling to cooperate with Wang Yibo again, Zhao Liying's fans went on a collective strike and made a public apology in less than a day
- JS function scope, closure, let, const
- Zheng Shuang's 30th birthday is deserted. Chen Jia has been sending blessings for ten years. Is it really just forgetting to make friends?
- Unveil the mystery of ascension
- Asynchronous solution async await
- Analysis and expansion of Vue infinite scroll source code
- Compression webpack plugin first screen loading optimization
- Specific usage of vue3 video play plug-in
- "The story of huiyeji" -- people are always greedy, and fairies should be spotless!
- Installing Vue devtool for chrome and Firefox
- Basic usage of JS object
- 1. JavaScript variable promotion mechanism
- Two easy-to-use animation JS that make the page move
- Front end Engineering - scaffold
- Java SQL Server intelligent fixed asset management, back end + front end + mobile end
- Mediator pattern of JavaScript Design Pattern
- Array de duplication problem solution - Nan recognition problem
- New choice for app development: building mobile applications using Vue native
- New gs8 Chengdu auto show announces interior Toyota technology blessing
- Vieira officially terminated his contract and left the team. The national security club sent blessings to him
- Less than 200000 to buy a Ford RV? 2.0T gasoline / diesel power, horizontal bed / longitudinal bed layout can be selected
- How does "heart 4" come to an end? Pinhole was boycotted by the brand, Ma Dong deleted the bad comments, and no one blessed him
- We are fearless in epidemic prevention and control -- pay tribute to the front-line workers of epidemic prevention!
- Front end, netty framework tutorial
- Xiaomi 11 | miui12.5 | android11 solves the problem that the httpcanary certificate cannot be installed
- The wireless charging of SAIC Roewe rx5 plus is so easy to use!
- Upload and preview pictures with JavaScript, and summarize the most complete mybatis core configuration file
- [25] typescript
- CSS transform Complete Guide (Second Edition) flight.archives 007
- Ajax foundation - HTTP foundation of interview essential knowledge
- Cloud lesson | explain in detail how Huawei cloud exclusive load balancing charges
- Decorator pattern of JavaScript Design Pattern
- [JS] 10. Closure application (loop processing)
- Left hand IRR, right hand NPV, master the password of getting rich