好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

实用的CSS

前言

在了解 cubic-bezier 之前,你需要对 CSS3 中的动画效果有所认识,它是 animation-timing-function 和 transition-timing-function 中一个重要的内容。

本体

简介

cubic-bezier 又称 三次贝塞尔 ,主要是为 animation 生成速度曲线的函数,规定是 cubic-bezier( , , , )。

我们可以从下图中简要理解一下 cubic-bezier:

从上图我们需要知道的是 cubic-bezier 的取值范围:

P0:默认值 (0, 0) P1:动态取值 (x1, y1) P2:动态取值 (x2, y2) P3:默认值 (1, 1)

我们需要关注的是 P1 和 P2 两点的取值,而其中 X 轴 的取值范围是 0 到 1 ,当取值超出范围时 cubic-bezier 将失效;Y 轴的取值没有规定,当然也毋须过大。

最直接的理解是,将 以一条直线放在范围只有 1 的坐标轴中,并从中间拿出两个点来拉扯(X 轴的取值区间是 [0, 1],Y 轴任意),最后形成的曲线就是动画的速度曲线 。

使用

在测试例子中:

         Document        .animation {      width: 50px;      height: 50px;      background-color: #ed3;      -webkit-transition:  all 2s;           -o-transition:  all 2s;              transition:  all 2s;    }    .animation:hover {      -webkit-transform:  translateX(100px);          -ms-transform:  translateX(100px);           -o-transform:  translateX(100px);              transform:  translateX(100px);    }       

查看更多关于实用的CSS的详细内容...

  阅读:28次