


Introduction to transition and animation properties of css3 animation
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 effectall: All attributes will obtain the transition effectporperty: width, height...img{ height:15px; width:15px; } img:hover{ height: 450px; width: 450px; }
img{ transition: 1s; }
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 heightimg{ transition: 1s height; }
img{ transition: 1s height, 1s width }
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 }
transition-timing-function state change speed
The default is to gradually slow down easePossible values are- linear: uniform speed
- easy-in: acceleration
- ease -out: deceleration
- cubic-bezier function, custom speed mode
Bezier Er curve)
cubic-bezier (img{ transition-property: height; transition-duration: 1s; transition-delay: 1s; transition-timing-function: ease; }
- Requires event triggering, which cannot occur directly when the web page is loaded
- It is a one-time event Yes, it cannot happen repeatedly unless you trigger it repeatedly
- Only the start state and the end state can be defined, and the intermediate state cannot be defined
- 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; }
上面代码表示,当鼠标悬停在p元素上时,会产生名为rainbow的动画效果,持续时间为1秒。为此,我们还需要用keyframes关键字,定义rainbow效果。
@keyframs rainbow{ 0% { background: #c00; } 50% { background: orange; } 100% { background: yellowgreen; } }
keyframs的写法相当自由
可以用from表示0%,to 表示100%
@keyframs rainbow{ from { background: #c00; } 50% { background: orange; } to { background: yellowgreen; } }
如果忽略某个状态,浏览器会自动推算
@keyframs rainbow{ 50% { background: orange; } to { background: yellowgreen; } } @keyframs rainbow{ to { background: yellowgreen; } } @keyframs rainbow{ from, to { background: yellowgreen; } }
浏览器从一个状态到另外一个状态是平滑过渡到,steps函数实现分步过渡
p:hover { animation: 1s rainbow infinite steps(10); }
默认情况下,动画只播放一次。加入infinite关键字,可以让动画无限次播放。
p:hover{ animation: 1s rainbow infinite; }
除了infinite,还可以设置为具体的次数: 3、5
p:hover{ animation: 1s rainbow 5; }
animation-fill-mode
动画结束以后会立即冲结束状态回到起始状态,如果想让动画保持在结束状态就要加上animation-fill-mode属性中的forwards
p:hover{ animation: 1s rainbow infinite forwards; }
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>
总结:以上就是本篇文的全部内容,希望能对大家的学习有所帮助。更多相关教程请访问 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!

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

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)

Hot Topics



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!

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

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 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

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!

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.

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;".

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!
