1. CSS animation
concept
When multiple still pictures are played at a certain speed, the naked eye will misperceive them as moving pictures.
Ii. Browser rendering principle
steps
- Building an HTML Tree (DOM)
- Building a CSS Tree (CSSDOM)
- Combine the above two trees into a render tree.
- Layout, document flow, box model, calculation size and location
- Paint, “Paint,” means to draw border colors, shadows, etc
- Compose, according to the cascade relationship display screen
Update the style
JS update style:
- div.style.background =’red’
- div.style.display =’none’
- div.classList.add(‘red’)
- Div.remove () deletes the node directly tips: Write styles during actual development
Update the way
- Div.remove () will trigger the current hour and other elements relayout
- Change the background color directly repaint+ Compasite
- Change transform only compasite
Animation optimization
- JS optimization: Use requestAnimationFrame instead of setTimeout or setlnterva
- CSS optimization: Use will-change or translate3
transform
- Translate translation
- Scale (overall, including all dimensions such as border width)
- The rotate rotating
- Skew tilt
B: Yes
role
Supplementary intermediate frame
usage
- Transition: Indicates the delay of the attribute name duration
- transition: left 200ms linear
- Transition: Left 200ms, Top 400ms You can use a comma to separate two different attributes
- Transition: All 200ms You can use all to represent all attributes
- Transition means has: linear | ease | ease – in | ease – out | ease – in-out | cubic bezier – | step – start | | step – end steps
Intransitive condition
- Display: None => Block cannot transition
- Visibility :hidden =>visible
- Background colors can transition
- Transitions must have a start, such as transitions between hover and non-hover states
4. Animation
@ keyframes grammar
- The from to the grammar
- Percentage grammar
Animation abbreviation syntax
Animation: | | transition way long delay | | | times direction whether filling | | suspended animation
- Duration: 1s or 1000ms
- Transition mode: takes the same value as transition, such as Linear
- Times: 3 or 2.4 or infinite
- Direction: reverse | alternate | alternate – reverse
- Filling pattern: none | recently | backwards | to both
- Whether to suspend: paused | running all these attributes have corresponding attributes separately