Home Web Front-end HTML Tutorial css3 animation attribute animation (animation)_html/css_WEB-ITnose

css3 animation attribute animation (animation)_html/css_WEB-ITnose

Jun 24, 2016 am 11:47 AM

Animation in CSS3 is different from Canvas drawing animation in HTML5. Animation is only applied to DOM elements that already exist on the page.

Using animation can create some animation effects you want, but it is a bit rough.

Before understanding animation, you must know "Keyframes", we call it "keyframe".

Keyframes has its own syntax rules. Its name starts with "@keyframes", followed by the "name of the animation" Add a pair of curly brackets "{}", and the brackets contain some style rules for different time periods, a bit like how we write CSS styles. For a style rule in "@keyframes" that is composed of multiple percentages, such as between "0%" and "100%", we can create multiple percentages in this rule, and we give each percentage a Elements with animation effects need to be added with different attributes, so that the elements can achieve a constantly changing effect, such as moving, changing element color, position, size, shape, etc. However, one thing to note is that we can use "From" and "to" represent where an animation starts and ends. In other words, "from" is equivalent to "0%" and "to" is equivalent to "100%". It is worth mentioning that, Among them, "0%" cannot omit the percent sign like other attribute values. We must add the percent sign ("%") here. If not, our keyframes will be invalid and will have no effect.

The unit of keyframes only accepts percentage values.

CSS3 animation is similar to the transition attribute. They both change the attribute value of the element over time. The main difference between them is that transition needs to trigger an event (hover event or click event, etc.) before it can change its css properties over time; animation can also change explicitly without triggering any events. Time changes to change the attribute value of the element's CSS to achieve an animation effect.

animation mainly has the following attributes:

1.animation-name;

2.animation-duration;

3.animation-timing- function;

4.animation-delay;

5.animation-iteration-count;

6.animation-direction;

7.animation- play-state
Next, we will introduce them one by one:

animation-name:

is used to define the name of an animation. None is the default value. When the value is none, there will be no animation effect.

animation-duration:

is used to specify the duration for the element to play animation.

animation-timing-function:

There are six ways to play animation: ease;ease-in;ease-in- out; linear; cubic-bezier.

animation-delay:

Specifies the time for element animation delay.

animation-iteration-count:

Specifies the number of cycles for the element to play animation, which can take the value as a number, and The default value is "1"; infinite is an infinite number of loops.

animation-direction:

is used to specify the direction of element animation playback. It has only two values. The default value is normal. If set When it is normal, each cycle of the animation plays forward; the other value is alternate, and its function is that the animation plays forward in the even-numbered times and in the reverse direction in the odd-numbered times.

animation-play-state:

is used to control the playback state of element animation. There are two main values, running and paused. running is the default value. The currently playing animation can be stopped by paused, or the paused animation can be replayed by running. If the animation is temporarily stopped, the element's style will return to the original setting state.

The following shows how to call animation:

.demo {     width: 50px;     height: 50px;     margin-left: 100px;     background: blue;     -webkit-animation-name:'ani-name';/*动画属性名,也就是我们前面keyframes定义的动画名*/     -webkit-animation-duration: 10s;/*动画持续时间*/     -webkit-animation-timing-function: ease-in-out; /*动画频率,和transition-timing-function是一样的*/     -webkit-animation-delay: 2s;/*动画延迟时间*/     -webkit-animation-iteration-count: 10;/*定义循环资料,infinite为无限次*/     -webkit-animation-direction: alternate;/*定义动画方式*/}
Copy after login
It can also be abbreviated:

.demo {     -webkit-animation:'ani-name' 10s ease-in-out 2s 10 alternate;}
Copy after login


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Is HTML easy to learn for beginners? Is HTML easy to learn for beginners? Apr 07, 2025 am 12:11 AM

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

What is an example of a starting tag in HTML? What is an example of a starting tag in HTML? Apr 06, 2025 am 12:04 AM

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Apr 04, 2025 pm 11:54 PM

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

How to use CSS3 and JavaScript to achieve the effect of scattering and enlarging the surrounding pictures after clicking? How to use CSS3 and JavaScript to achieve the effect of scattering and enlarging the surrounding pictures after clicking? Apr 05, 2025 am 06:15 AM

To achieve the effect of scattering and enlarging the surrounding images after clicking on the image, many web designs need to achieve an interactive effect: click on a certain image to make the surrounding...

How to implement adaptive layout of Y-axis position in web annotation? How to implement adaptive layout of Y-axis position in web annotation? Apr 04, 2025 pm 11:30 PM

The Y-axis position adaptive algorithm for web annotation function This article will explore how to implement annotation functions similar to Word documents, especially how to deal with the interval between annotations...

HTML, CSS, and JavaScript: Essential Tools for Web Developers HTML, CSS, and JavaScript: Essential Tools for Web Developers Apr 09, 2025 am 12:12 AM

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

See all articles