How to play with css animation? (organize and share)
This article brings you relevant knowledge about animation in CSS, including what animation is, how to call animation, and how to implement multi-keyframe animation. I hope it will be helpful to you.
1. What is animation
In CSS, you can use @keyframes to define animation
(keyframes means " Keyframe")
General structure:
@keyframes rotation { /* rotation 动画名 */ from { /* 起始状态 */ transform: rotate(0); } to { /* 结束状态 */ transform: rotate(360deg); }}
2. Calling animation
After defining the animation, you can use the animation attribute to call the animation.
Basic attributes of animation:
- name: the name of the animation
(initial default value none) - duration: animation duration
(initial default value 0s) - timing function: change speed curve
(initial default value ease) - delay: delay time (how much time passes before the animation starts)
(initial default value 0s) - iteration-count: Number of animation executions
(Initial default value 1, if you want the animation to execute forever, write infinite)
animation: name | duration | timing function | delay | iteration-count;
In addition, there are some attributes :
animation-direction (Set whether to play the animation in reverse in turn)
- normal: Play the animation in the normal way (initial default value)
- reverse: Play the animation in the opposite way
- alternate: Let the 2nd, 4th, 6th... (even-numbered times) of the animation be automatically reversed
- alternate-reverse: Let the odd numbers of the animation be executed Automatic reverse execution
animation-fill-mode (set the state of the animation when the animation is not playing)
- none: No Change the default behavior of animation
- forwards: Stop the animation at the final end state
- backwards: Apply the style in the first keyframe of the animation during the time period specified by animation-delay
- both: Follow the rules of forwards and backwards at the same time
animation-play-state (set whether the animation is played or paused)
- paused: Pause animation playback
- running: Play animation normally
3. Multi-keyframe animation
For those who want to achieve multiple For animation with this effect, you can use multiple keyframes at this time.
General structure:
@keyframes changeColor { 0% { background-color: red; } 20% { background-color: orange; } 40% { background-color: blue; } 100% { background-color: green; }}
(Learning video sharing: css video tutorial)
The above is the detailed content of How to play with css animation? (organize and share). For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

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

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

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)

To change the text color in CSS, you need to use the color attribute; 1. Use the color attribute to set the text foreground color, supporting color names (such as red), hexadecimal codes (such as #ff0000), RGB values (such as rgb(255,0,0)), HSL values (such as hsl(0,100%,50%)), and RGBA or HSLA with transparency (such as rgba(255,0,0,0.5)); 2. You can apply colors to any element containing text, such as h1 to h6 titles, paragraph p, link a (note the color settings of different states of a:link, a:visited, a:hover, a:active), buttons, div, span, etc.; 3. Most

In web development, the choice of CSS units depends on design requirements and responsive performance. 1. Pixels (px) are used to fix sizes such as borders and icons, but are not conducive to responsive design; 2. Percentage (%) is adjusted according to the parent container, suitable for streaming layout but attention to context dependence; 3.em is based on the current font size, rem is based on the root element font, suitable for elastic fonts and unified theme control; 4. Viewport units (vw/vh/vmin/vmax) are adjusted according to the screen size, suitable for full-screen elements and dynamic UI; 5. Auto, inherit, initial and other values are used to automatically calculate, inherit or reset styles, which helps to flexibly layout and style management. The rational use of these units can improve page flexibility and responsiveness.

Backdrop-filter is used to apply visual effects to the content behind the elements. 1. Use backdrop-filter:blur(10px) and other syntax to achieve the frosted glass effect; 2. Supports multiple filter functions such as blur, brightness, contrast, etc. and can be superimposed; 3. It is often used in glass card design, and it is necessary to ensure that the elements overlap with the background; 4. Modern browsers have good support, and @supports can be used to provide downgrade solutions; 5. Avoid excessive blur values and frequent redrawing to optimize performance. This attribute only takes effect when there is content behind the elements.

The style of the link should distinguish different states through pseudo-classes. 1. Use a:link to set the unreached link style, 2. a:visited to set the accessed link, 3. a:hover to set the hover effect, 4. a:active to set the click-time style, 5. a:focus ensures keyboard accessibility, always follow the LVHA order to avoid style conflicts. You can improve usability and accessibility by adding padding, cursor:pointer and retaining or customizing focus outlines. You can also use border-bottom or animation underscore to ensure that the link has a good user experience and accessibility in all states.

User agent stylesheets are the default CSS styles that browsers automatically apply to ensure that HTML elements that have not added custom styles are still basic readable. They affect the initial appearance of the page, but there are differences between browsers, which may lead to inconsistent display. Developers often solve this problem by resetting or standardizing styles. Use the Developer Tools' Compute or Style panel to view the default styles. Common coverage operations include clearing inner and outer margins, modifying link underscores, adjusting title sizes and unifying button styles. Understanding user agent styles can help improve cross-browser consistency and enable precise layout control.

Define@keyframesbouncewith0%,100%attranslateY(0)and50%attranslateY(-20px)tocreateabasicbounce.2.Applytheanimationtoanelementusinganimation:bounce0.6sease-in-outinfiniteforsmooth,continuousmotion.3.Forrealism,use@keyframesrealistic-bouncewithscale(1.1

Use the border attribute to set the dashed style to quickly create dotted lines, such as border-top:2pxdashed#000; 2. You can customize the appearance of the dotted line by adjusting the border width, color and style; 3. When applying the dotted line to dividers or inline elements, it is recommended to set height:0 or reset the default style of hr; 4. If you need to accurately control the length and spacing of the dotted line, you should use background-image and linear-gradient to cooperate with linear-gradient, for example, background:linear-gradient(toright, black33%, transparent33%) repe

To achieve CSS element overlap, you need to use positioning and z-index attributes. 1. Use position and z-index: Set elements to non-static positioning (such as absolute, relative, etc.), and control the stacking order through z-index, the larger the value, the higher the value. 2. Common positioning methods: absolute is used for precise layout, relative is used for relatively offset and overlap adjacent elements, fixed or sticky is used for fixed positioning of suspended layers. 3. Actual example: By setting the parent container position:relative, child element position:absolute and different z-index, the card overlap effect can be achieved.
