transition-timing-function
CSS property sets how intermediate values are calculated for CSS properties being affected by a
transition effect
.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
This, in essence, lets you establish an acceleration curve so that the speed of the transition can vary over its duration.
This acceleration curve is defined using one
<timing-function>
for each property to be transitioned.
You may specify multiple timing functions; each one will be applied to the corresponding property as specified by the
transition-property
property, which acts as a
transition-property
list. If there are fewer timing functions specified than in the
transition-property
list, the user agent must calculate which value is used by repeating the list of values until there is one for each transition property. If there are more timing functions, the list is simply truncated to the right size. In both cases, the CSS declaration stays valid.
/* Keyword values */ transition-timing-function: ease; transition-timing-function: ease-in; transition-timing-function: ease-out; transition-timing-function: ease-in-out; transition-timing-function: linear; transition-timing-function: step-start; transition-timing-function: step-end; /* Function values */ transition-timing-function: steps(4, jump-end); transition-timing-function: cubic-bezier(0.1, 0.7, 1.0, 0.1); /* Steps Function keywords */ transition-timing-function: steps(4, jump-start); transition-timing-function: steps(10, jump-end); transition-timing-function: steps(20, jump-none); transition-timing-function: steps(5, jump-both); transition-timing-function: steps(6, start); transition-timing-function: steps(8, end); /* Multiple timing functions */ transition-timing-function: ease, step-start, cubic-bezier(0.1, 0.7, 1.0, 0.1); /* Global values */ transition-timing-function: inherit; transition-timing-function: initial; transition-timing-function: unset;
<timing-function>
<timing-function>
represents the timing function to link to the corresponding property to transition, as defined in
transition-property
.
The non-step keyword values (ease, linear, ease-in-out, etc.) each represent cubic Bézier curve with fixed four point values, with the cubic-bezier() function value allowing for a non-predefined value. The step timing functions divides the input time into a specified number of intervals that are equal in length. It is defined by a number of steps and a step position.
ease
cubic-bezier(0.25, 0.1, 0.25, 1.0)
, the default value, increases in velocity towards the middle of the transition, slowing back down at the end.
linear
cubic-bezier(0.0, 0.0, 1.0, 1.0)
, transitions at an even speed.
ease-in
cubic-bezier(0.42, 0, 1.0, 1.0)
, starts off slowly, with the transition speed increasing until complete.
ease-out
cubic-bezier(0, 0, 0.58, 1.0)
, starts transitioning quickly, slowing down the transition continues. •
ease-in-out
cubic-bezier(0.42, 0, 0.58, 1.0)
, starts transitioning slowly, speeds up, and then slows down again.
cubic-bezier(p1, p2, p3, p4)
An author defined cubic-Bezier curve, where the p1 and p3 values must be in the range of 0 to 1.
steps( n, <jumpterm>)
jump-start
Denotes a left-continuous function, so that the first jump happens when the transition begins;
jump-end
Denotes a right-continuous function, so that the last jump happens when the animation ends;
jump-none
There is no jump on either end. Instead, holding at both the 0% mark and the 100% mark, each for 1/n of the duration
jump-both
Includes pauses at both the 0% and 100% marks, effectively adding a step during the transition time.
start
jump-start.
end
jump-end.
step-start
steps(1, jump-start)
step-end
steps(1, jump-end)
Some animations can be helpful such as to guide users to understand what actions are expected, to show relationships within the user interface, and to inform users as to what actions have occurred. Animations can help reduce cognitive load, prevent change blindness, and establish better recall in spatial relationships. However, some animations can be problematic for people with cognitive concerns such as Attention Deficit Hyperactivity Disorder (ADHD) and certain kinds of motion can be a trigger for Vestibular disorders, epilepsy, and migraine and Scotopic sensitivity.
Consider providing a mechanism for pausing or disabling animation, as well as using the Reduced Motion Media Query to create a complimentary experience for users who have expressed a preference for no animated experiences.
| 初始值 |
ease
|
|---|---|
| 适用于 |
所有元素,
::before
and
::after
pseudo-elements
|
| 继承 | no |
| 计算值 | 如指定 |
| 动画类型 | discrete |
<timing-function>#where
<timing-function> = linear | <cubic-bezier-timing-function> | <step-timing-function>where
<cubic-bezier-timing-function> = ease | ease-in | ease-out | ease-in-out | cubic-bezier(<number <a href="/en-US/docs/CSS/Value_definition_syntax#Brackets" title="Brackets: enclose several entities, combinators, and multipliers to transform them as a single component">[0,1]>, <number>, <number <a href="/en-US/docs/CSS/Value_definition_syntax#Brackets" title="Brackets: enclose several entities, combinators, and multipliers to transform them as a single component">[0,1]>, <number>)
<step-timing-function> = step-start | step-end | steps(<integer>[, <step-position>]?)where
<step-position> = jump-start | jump-end | jump-none | jump-both | start | end
<div class="parent"> <div class="ease">ease</div> <div class="easein">ease-in</div> <div class="easeout">ease-out</div> <div class="easeinout">ease-in-out</div> <div class="linear">linear</div> <div class="cb">cubic-bezier(0.2,-2,0.8,2)</div> </div>
.parent {}
.parent > div[class] {
width: 12em;
min-width: 12em;
margin-bottom: 4px;
background-color: black;
border: 1px solid red;
color: white;
transition-property: all;
transition-duration: 7s;
}
.parent > div.box1{
width: 90vw;
min-width: 24em;
background-color: magenta;
color: yellow;
border: 1px solid orange;
transition-property: all;
transition-duration: 2s;
}
function updateTransition() {
var els = document.querySelectorAll(".parent > div[class]");
for(var c = els.length, i = 0; i < c; i++) {
els[i].classList.toggle("box1");
}
}
var intervalID = window.setInterval(updateTransition, 10000);
.ease {
transition-timing-function: ease;
}
.easein {
transition-timing-function: ease-in;
}
.easeout {
transition-timing-function: ease-out;
}
.easeinout {
transition-timing-function: ease-in-out;
}
.linear {
transition-timing-function: linear;
}
.cb {
transition-timing-function: cubic-bezier(0.2,-2,0.8,2);
}
<div class="parent"> <div class="jump-start">jump-start</div> <div class="jump-end">jump-end</div> <div class="jump-both">jump-both</div> <div class="jump-none">jump-none</div> <div class="step-start">step-start</div> <div class="step-end">step-end</div> </div>
.parent {}
.parent > div[class] {
width: 12em;
min-width: 12em;
margin-bottom: 4px;
background-color: black;
border: 1px solid red;
color: white;
transition-property: all;
transition-duration:7s;
}
.parent > div.box1{
width: 90vw;
min-width: 24em;
background-color: magenta;
color: yellow;
border: 1px solid orange;
transition-property: all;
transition-duration:2s;
}
function updateTransition() {
var els = document.querySelectorAll(".parent > div[class]");
for(var c = els.length, i = 0; i < c; i++) {
els[i].classList.toggle("box1");
}
}
var intervalID = window.setInterval(updateTransition, 10000);
.jump-start {
transition-timing-function: steps(5, jump-start);
}
.jump-end {
transition-timing-function: steps(5, jump-end);
}
.jump-none {
transition-timing-function: steps(5, jump-none);
}
.jump-both {
transition-timing-function: steps(5, jump-both);
}
.step-start {
transition-timing-function: step-start;
}
.step-end {
transition-timing-function: step-end;
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
CSS Transitions
The definition of 'transition-timing-function' in that specification. |
工作草案 | 初始定义 |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
transition-timing-function
|
Chrome 完整支持 26 | Edge 完整支持 12 |
Firefox
完整支持
16
|
IE
完整支持
10
|
Opera
完整支持
12.1
|
Safari 完整支持 9 | WebView Android 完整支持 ≤37 | Chrome Android 完整支持 26 |
Firefox Android
完整支持
16
|
Opera Android
完整支持
12.1
|
Safari iOS 完整支持 9 | Samsung Internet Android 完整支持 1.5 |
jump-
keywords for
steps()
|
Chrome 完整支持 77 | Edge 完整支持 79 | Firefox 完整支持 65 | IE 不支持 No | Opera 完整支持 64 | Safari 完整支持 14 | WebView Android 完整支持 77 | Chrome Android 完整支持 77 | Firefox Android 完整支持 65 | Opera Android 完整支持 55 | Safari iOS 完整支持 14 | Samsung Internet Android 完整支持 12.0 |
完整支持
不支持
用户必须明确启用此特征。
要求使用供应商前缀或不同名称。
transition
transition-property
transition-duration
transition-delay
TransitionEvent
transition
transition-delay
transition-duration
transition-property
transition-timing-function