Through transition, web front-end developers can achieve simple animation interaction effects without JavaScript. Transition properties may seem simple, but in fact there are a lot of details to pay attention to and things that can be confusing. This article will introduce and sort out the knowledge about CSS transition
Definition
Transition is a composite property, including transition-property, transition-duration, transition-timing-function , transition-delay these four sub-attributes. A complete transition effect can be completed through the cooperation of these four sub-attributes
1
2
3
4
transition-property: 过渡属性(默认值为all)
transition-duration: 过渡持续时间(默认值为0s)
transiton-timing-function: 过渡函数(默认值为ease函数)
transition-delay: 过渡延迟时间(默认值为0s)
Copy after login
[Note] IE9-does not support this attribute, safari3 .1-6, IOS3.2-6.1, android2.1-4.3 need to add the -webkit- prefix; while other higher version browsers support the standard writing
1
2
3
4
5
6
7
8
9
10
11
.test{
height: 100px;
width: 100px;
background-color: pink;
transition-duration: 3s;/* 以下三值为默认值,稍后会详细介绍 */
transition-property: all;
transition-timing-function: ease;
transition-delay: 0s;
} .test:hover{
width: 500px;
}
Copy after login
1
<p class="test"></p>
Copy after login
//Move the mouse over the element, and the width change effect will appear
Composite attributes
Of the four sub-attributes of transition, only is a required value and cannot be 0. Among them, and are both times. When two times occur at the same time, the first is , and the second is ; when there is only one time, it is , and is the default value 0
[Note] The four sub-properties of transition cannot be separated by commas, only Separate with spaces. Because the ones separated by commas represent different attributes (the transition attribute supports multi-value, and the multi-value part will be introduced later); and the ones separated by spaces represent four sub-attributes about transition
The unit of this attribute is seconds or milliseconds ms
transition-duration
Value:
Initial value: 0s
Applies to: all elements
Inheritance: None
[Note] This attribute cannot be a negative value
[Note] If the attribute is 0s, it is the default value, if it is 0, it is an invalid value . Therefore, the unit must be
[Note] When the value is a single value, all transition attributes correspond to the same time; when the value is multi-value, the transition attributes correspond to the duration in order
This attribute defines how long the element attribute is delayed After the transition effect starts, the unit of this attribute is seconds s or milliseconds ms
transition-delay
Value: [,]*
Initial value: 0s
Applies to: all elements
Inheritance: None
[Note] If this attribute is a negative value, there will be no delay effect, but the start of the transition element will The initial value will change from 0 to the set value (set value = delay time + duration). If the setting value is less than or equal to 0, there will be no transition effect; if the setting value is greater than 0, the transition element will complete the remaining transition effect starting from the setting value
[Note] If this attribute is 0s It is the default value, if it is 0, it is an invalid value. Therefore, the unit must be
[Note] When the value is a single value, all transition attributes correspond to the same time; when the value is multi-value, the transition attributes correspond to the duration in order
The transition time function is used to define the transition of elements The effect of transition speed change of attributes over time
transition-timing-function
Value: [,]*
Initial value: ease
Applies to: all elements
Inheritance: None
Value
There are three values for the transition time function, namely Keywords, steps function and bezier function
steps function
The steps step function divides the transition time into equal-sized time intervals to run
The steps step function is
1
steps(<integer>[,start | end]?)
Copy after login
1
2
<integer>:用来指定间隔个数(该值只能是正整数)
第二个参数: 该参数可选,默认是end,表示开始值保持一次;若参数为start,表示开始不保持
Copy after login
Bezier curve
The Bezier curve is controlled by four control points p0-p3, where p0 represents (0,0) and p3 represents (1 ,1). And is determined by determining the values of p1(x1,y1) and p2(x2,y2)
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