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!

两种方法:1、利用display属性,只需给元素添加“display:none;”样式即可。2、利用position和top属性设置元素绝对定位来隐藏元素,只需给元素添加“position:absolute;top:-9999px;”样式。

怎么制作文字轮播与图片轮播?大家第一想到的是不是利用js,其实利用纯CSS也能实现文字轮播与图片轮播,下面来看看实现方法,希望对大家有所帮助!

实现方法:1、使用“:active”选择器选中鼠标点击图片的状态;2、使用transform属性和scale()函数实现图片放大效果,语法“img:active {transform: scale(x轴放大倍数,y轴放大倍数);}”。

自适应布局又称“响应式布局”,是指可以自动识别屏幕宽度、并做出相应调整的网页布局;这样的网页能够兼容多个不同的终端,而不是为每个终端做一个特定的版本。自适应布局是为解决移动端浏览网页而诞生的,能够为使用不同终端的用户提供很好的用户体验。

css3中的动画效果有变形;可以利用“animation:动画属性 @keyframes ..{..{transform:变形属性}}”实现变形动画效果,animation属性用于设置动画样式,transform属性用于设置变形样式。

在css3中,可以利用“animation-timing-function”属性设置动画旋转速度,该属性用于指定动画将如何完成一个周期,设置动画的速度曲线,语法为“元素{animation-timing-function:速度属性值;}”。

css3线性渐变可以实现三角形;只需创建一个45度的线性渐变,设置渐变色为两种固定颜色,一个是三角形的颜色,另一个为透明色即可,语法“linear-gradient(45deg,颜色值,颜色值 50%,透明色 50%,透明色 100%)”。

本篇文章带大家一起深入了解一下CSS3中的新特性::target-text 选择器,聊聊该选择器的作用和使用方法,希望对大家有所帮助!


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version
Visual web development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool