Home Web Front-end CSS Tutorial Introduction to transition and animation properties of css3 animation

Introduction to transition and animation properties of css3 animation

Oct 11, 2018 pm 04:07 PM
animation css3 css3 animation transition

This article will introduce to you the transition and animation attributes for realizing CSS3 animation. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

tradition has a total of 4 properties:

  • ##transition-property transition property

  • Transition-duration The time required to complete the animation, calculated in seconds or milliseconds

  • transition-timing-function specifies the animation change speed curve

  • transition-delay Whether to delay

transition-property Transition property

none: No properties will be obtained Transition effect

all: All attributes will obtain the transition effect

porperty: width, height...

img{    
    height:15px;    
    width:15px;
}
img:hover{    
    height: 450px;    
    width: 450px;
}
Copy after login
The function of transition is to specify the time required for state changes.

img{
    transition: 1s;
}
Copy after login

transition-duration seconds or milliseconds to complete the state transition

You can also specify the change attribute of the transition, such as width change or height

img{
    transition: 1s height;
}
Copy after login
Multiple attributes can also be specified

img{
    transition: 1s height, 1s width
}
Copy after login

transition-delay state change speed.

Specify the delay parameter so that the height changes first, and then the width changes:

img{
    transition: 1s height, 1s 1s width
}
Copy after login
The real meaning of delay is to specify the order in which the animation occurs, so that multiple different Transition can occur at different moments to form an animation effect

transition-timing-function state change speed

The default is to gradually slow down ease

Possible values ​​are

  • linear: uniform speed

  • easy-in: acceleration

  • ease -out: deceleration

  • cubic-bezier function, custom speed mode

(cubic: cubic, bezier:

Bezier Er curve)

cubic-bezier (, , , ) value range 0-1

img{    
    transition-property: height;         
    transition-duration: 1s;    
    transition-delay: 1s;    
    transition-timing-function: ease;
}
Copy after login
Note :Transition requires clear knowledge of the specific values ​​of the start state and end state in order to calculate the intermediate state. But the transition cannot calculate the state of 0->auto, so there will be no animation effect. Similar situations include display: none->block and background:url(foo.jpg)->url(bar.jpg).

It has some disadvantages:

  1. Requires event triggering, which cannot occur directly when the web page is loaded

  2. It is a one-time event Yes, it cannot happen repeatedly unless you trigger it repeatedly

  3. Only the start state and the end state can be defined, and the intermediate state cannot be defined

  4. A transition Rules can only define changes to one attribute

animation

CSS Animation has the following attributes:

  • animation-name The name that needs to be bound to the selector keyframe

  • animation-duration The time required to complete the animation, calculated in seconds or milliseconds

  • animation-timing-function specifies the speed curve of the animation

  • animaton-delay The delay time before the animation starts

  • animation-iteration-count The number of times the animation should be played

  • animation-direction Whether the animation should be played in reverse in turn

  • animation-fill -mode attribute specifies whether the dynamic effect is visible after the animation is played

  • animatoin-play-state specifies whether the animation is running or paused

iteration-repeat

animation-name

animation-duration

首先 设置动画的名称和持续的时长

p:hover{
animation: 1s rainbow;
}
Copy after login

上面代码表示,当鼠标悬停在p元素上时,会产生名为rainbow的动画效果,持续时间为1秒。为此,我们还需要用keyframes关键字,定义rainbow效果。

@keyframs rainbow{
0% { background: #c00; }
50% { background: orange; }
100% { background: yellowgreen; }
}
Copy after login

keyframs的写法相当自由

可以用from表示0%,to 表示100%

@keyframs rainbow{
from { background: #c00; }
50% { background: orange; }
to { background: yellowgreen; }
}
Copy after login

如果忽略某个状态,浏览器会自动推算

@keyframs rainbow{
   50% { background: orange; }
     to { background: yellowgreen; }
}

@keyframs rainbow{
to { background: yellowgreen; }
}

@keyframs rainbow{
from, to { background: yellowgreen; }
}
Copy after login

浏览器从一个状态到另外一个状态是平滑过渡到,steps函数实现分步过渡

p:hover {
animation: 1s rainbow infinite steps(10);
}
Copy after login

默认情况下,动画只播放一次。加入infinite关键字,可以让动画无限次播放。

p:hover{
animation: 1s rainbow infinite;
}
Copy after login

除了infinite,还可以设置为具体的次数: 3、5

p:hover{
animation: 1s rainbow 5;
}
Copy after login

animation-fill-mode

动画结束以后会立即冲结束状态回到起始状态,如果想让动画保持在结束状态就要加上animation-fill-mode属性中的forwards

p:hover{
animation: 1s rainbow infinite forwards;
}
Copy after login

animation-fill-mode 有4种取值

none 不改变默认行为

forawads 动画完成后,保持最后一个属性(在最后一个关键帧中定义)

backwards 在 animation-delay 所指定的一段时间内,在动画显示之前,应用开始属性值(在第一个关键帧中定义)。

both 向前向后都进行填充

animation-direction

规定了轮流反向播放动画

alternate:动画会在奇数次(1,3,5...)正常播放,偶数次(2,4,6...)反向播放

最常用alternate和revers,浏览器对其他值的支持不佳

<iframe 
width="100%" height="300" src="//jsfiddle.net/xiaoying/2414dr39/embedded/">
</iframe>
Copy after login

总结:以上就是本篇文的全部内容,希望能对大家的学习有所帮助。更多相关教程请访问 CSS3视频教程

相关推荐:

php公益培训视频教程

CSS在线手册

CSS3在线手册

div/css图文教程

css3特效代码大全

The above is the detailed content of Introduction to transition and animation properties of css3 animation. For more information, please follow other related articles on the PHP Chinese website!

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

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)

How to achieve wave effect with pure CSS3? (code example) How to achieve wave effect with pure CSS3? (code example) Jun 28, 2022 pm 01:39 PM

How to achieve wave effect with pure CSS3? This article will introduce to you how to use SVG and CSS animation to create wave effects. I hope it will be helpful to you!

How to speed up animation effects in Windows 11: 2 methods explained How to speed up animation effects in Windows 11: 2 methods explained Apr 24, 2023 pm 04:55 PM

When Microsoft launched Windows 11, it brought a lot of changes. One of the changes is an increase in the number of user interface animations. Some users want to change the way things appear, and they have to find a way to do it. Having animations makes it feel better and more user-friendly. Animation uses visual effects to make the computer look more attractive and responsive. Some of them include sliding menus after a few seconds or minutes. There are many animations on your computer that can affect PC performance, slow it down, and interfere with your work. In this case you have to turn off animation. This article will introduce several ways that users can improve the speed of their animations on PC. You can apply the changes using Registry Editor or a custom file you run. How to improve animations in Windows 11

CSS tip: Use transition to retain hover state CSS tip: Use transition to retain hover state Sep 27, 2022 pm 02:01 PM

How to preserve hover state? The following article will introduce to you how to retain the hover state without using JavaScript. I hope it will be helpful to you!

How to use CSS to achieve the rotating background animation effect of elements How to use CSS to achieve the rotating background animation effect of elements Nov 21, 2023 am 09:05 AM

How to use CSS to implement rotating background image animation effects of elements. Background image animation effects can increase the visual appeal and user experience of web pages. This article will introduce how to use CSS to achieve the rotating background animation effect of elements, and provide specific code examples. First, we need to prepare a background image, which can be any picture you like, such as a picture of the sun or an electric fan. Save the image and name it "bg.png". Next, create an HTML file and add a div element in the file, setting it to

Use CSS skillfully to realize various strange-shaped buttons (with code) Use CSS skillfully to realize various strange-shaped buttons (with code) Jul 19, 2022 am 11:28 AM

This article will show you how to use CSS to easily realize various weird-shaped buttons that appear frequently. I hope it will be helpful to you!

How to hide elements in css without taking up space How to hide elements in css without taking up space Jun 01, 2022 pm 07:15 PM

Two methods: 1. Using the display attribute, just add the "display:none;" style to the element. 2. Use the position and top attributes to set the absolute positioning of the element to hide the element. Just add the "position:absolute;top:-9999px;" style to the element.

How to implement lace borders in css3 How to implement lace borders in css3 Sep 16, 2022 pm 07:11 PM

In CSS, you can use the border-image attribute to achieve a lace border. The border-image attribute can use images to create borders, that is, add a background image to the border. You only need to specify the background image as a lace style; the syntax "border-image: url (image path) offsets the image border width inward. Whether outset is repeated;".

It turns out that text carousel and image carousel can also be realized using pure CSS! It turns out that text carousel and image carousel can also be realized using pure CSS! Jun 10, 2022 pm 01:00 PM

How to create text carousel and image carousel? The first thing everyone thinks of is whether to use js. In fact, text carousel and image carousel can also be realized using pure CSS. Let’s take a look at the implementation method. I hope it will be helpful to everyone!

See all articles