Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

CSS cubic-bezier() Function

CSS cubic-bezier() Function

CSS Functions CSS Functions

Example

A transition with different speeds from start to end:

div

{

width:

100

px

;

height:

100

px

;

background:

red

;

transition:

width

2

s

;

transition-timing-function:

cubic-bezier

(

0.1

,

0.7

,

1.0

,

0.1

)

;

}

Try it »


Definition and usage

The cubic-bezier() function defines a Cubic Bezier curve.

A Bezier curve is defined by four points P0, P1, P2, and P3. P0 and P3 are the start and end points of the curve. P0 is (0,0), representing the initial time and initial state, and P3 is (1,1), representing the final time and final state.

From the figure above we need to know the value range of cubic-bezier:

P0:默认值 (0, 0)

P1:动态取值 (x1, y1)

P2:动态取值 (x2, y2)

P3:默认值 (1, 1)

We need to focus on the values of P1 and P2. The X-axis ranges from 0 to 1; when a value is out of range, cubic-bezier becomes invalid. The Y-axis has no restriction, and of course need not be too large.

The most direct understanding is to place a straight line in a coordinate system with a range of only 1, then pull two points out from the middle (X-axis range is [0, 1], Y-axis arbitrary); the resulting curve is the animation's speed curve.

cubic-bezier() can be used for animation-timing-function and transition-timing-function attribute.

Supported version: CSS3


Browser support

The numbers in the table indicate the first browser version that supports the function.

function
cubic-bezier() 4.0 10.0 4.0 3.1 10.5

CSS Syntax



cubic-bezier(x1,y1,x2,y2)

Value Description
x1,y1,x2,y2 Required. Numeric values; x1 and x2 must be numbers between 0 and 1.

CSS Functions CSS Functions