The last challenge introduced the animation-timing-function property and a few keywords that change the speed of an animation over its duration.

CSS offers an option other than keywords that provides even finer control over how the animation plays out, through the use of Bezier curves.

In CSS animations, Bezier curves are used with the cubic-bezier function.

The shape of the curve represents how the animation plays out.

The curve lives on a 1 by 1 coordinate system.

The X-axis of this coordinate system is the duration of the animation (think of it as a time scale), and the Y-axis is the change in the animation.

The cubic-bezier function consists of four main points that sit on this 1 by 1 grid: p0p1p2, and p3p0 and p3 are set for you - they are the beginning and end points which are always located respectively at the origin (0, 0) and (1, 1).

You set the x and y values for the other two points, and where you place them in the grid dictates the shape of the curve for the animation to follow.

This is done in CSS by declaring the x and y values of the p1 and p2 "anchor" points in the form: (x1, y1, x2, y2).

Pulling it all together, here's an example of a Bezier curve in CSS code:

animation-timing-function: cubic-bezier(0.25, 0.25, 0.75, 0.75);

In the example above, the x and y values are equivalent for each point (x1 = 0.25 = y1 and x2 = 0.75 = y2), which if you remember from geometry class, results in a line that extends from the origin to point (1, 1). This animation is a linear change of an element during the length of an animation, and is the same as using the linear keyword.

In other words, it changes at a constant speed.

练习题目:

For the element with the id of ball1, change the value of the animation-timing-function property from linear to its equivalent cubic-bezier function value.

Use the point values given in the example above.

练习代码:

 <style>

   .balls{
border-radius: 50%;
background: linear-gradient(
35deg,
#ccffff,
#ffcccc
);
position: fixed;
width: 50px;
height: 50px;
margin-top: 50px;
animation-name: bounce;
animation-duration: 2s;
animation-iteration-count: infinite;
}
#ball1 {
left: 27%;
animation-timing-function: cubic-bezier(0.25, 0.25, 0.75, 0.75);
}
#ball2 {
left: 56%;
animation-timing-function: ease-out;
} @keyframes bounce {
0% {
top: 0px;
}
100% {
top: 249px;
}
} </style> <div class="balls" id="ball1"></div>
<div class="balls" id="ball2"></div>

效果如下:

我的理解,也是2个球掉下,相同循环时间,你定义坐标轴2个点的值,再加上原点和(1,1),形成的曲线。

X轴是循环时间段,Y轴是变化值。例如,X是0.1,Y是0.9,意味在很少的时间内变化很大的值,速度会比较快。

具体也是调试数值,可以体会效果

FCC---Learn How Bezier Curves Work---定义坐标轴点的值,影响斜率,改变速度。具体调试换值既可以体会的更多相关文章

  1. OpenCASCADE Rational Bezier Curves

    OpenCASCADE Rational Bezier Curves eryar@163.com Abstract. Although polynomials offer many advantage ...

  2. vue中如果在页面中v-model的是字典,那么在定义字典的时候,需要明确定义键值为''或者[],否则给字典的键值赋值后页面不显示

    如题 在template模板中 {{}} {{form_temp.blOwnerMemberList}} #是字典的形式哦 {{}} 在return的属性中 form_temp: { blOwnerM ...

  3. ie6下标签定义的高失效,显示的高不受设定的height值影响

    今天又碰到一个奇葩的ie6兼容bug,忍不住抱怨下这个后妈生的鬼东西!! 看图这个是在非ie6下的浏览器效果

  4. LINQ 用法,返回结果不是在定义时取值,而是在调用时实时取值,有意思!

    var names = new List<string> { "Nino o", "Alberto", "Juan", &quo ...

  5. Enum定义位域, 即可以通过位操作来产生未命名的值

    通过FlagsAttribute可以实现. // A bit field or flag enumeration of harvesting seasons. [Flags] public enum ...

  6. CSS3参数matrix(n,n,n,n,n,n)定义 2D 转换,使用六个值的矩阵。那这六个值分别代表了什么参数?

    matrix( a, b, c, d, e, f );a 水平缩放b 水平倾斜c 垂直倾斜d 垂直缩放e 水平移动f 垂直移动

  7. Unity API 解析 (陈泉宏著)

    1 Application类 2 Camera类 3 GameObject类 4 HideFlags类 5 Mathf类 6 Matrix4x4类 7 Object类 8 Quaternion类 9 ...

  8. [Fundamental of Power Electronics]-PART II-8. 变换器传递函数-8.1 Bode图回顾

    8.0 序 工程设计过程主要包括以下几个过程: 1.定义规格与其他设计目标 2.提出一个电路.这是一个创造性的过程,需要利用工程师的实际见识和经验. 3.对电路进行建模.变换器的功率级建模方法已经在第 ...

  9. 类型基础---CLR Via C#笔记一

    一.所有类型都是从System.Obejct派生 1.下面两个类型定义是完全一致的: class Employee{ ... } class Employee:System.Object{ ... } ...

随机推荐

  1. Net Core的API文档工具Swagger

    一.安装swagger 新建一个net core的api项目,通过NuGet安装Swashbuckle.AspNetCore. 二.注册swagger服务 在Startup.cs中注册Swagger生 ...

  2. cocos2d-x 新工程的把玩

    创建了cocos的工程以及初步了解了工程的结构之后,可以尝试自己改改代码了 游戏窗口的设置 首先是AppDelegate,找到AppDelegate.cpp中AppDelegate::applicat ...

  3. T-SQL语句操作数据库——基本操作

    一.创建删除数据数据库 1.T-SQL语句创建数据库语法如下: CREATE DATABASE 数据库名 ON [PRINARY] ( <文件参数>[,...n] [<文件组参数&g ...

  4. OpenCV:获取图像当中某一点的坐标

    import numpy as np image=np.zeros((300,300,3),dtype='uint8') (cx,cy)=image.shape[1]//2,image.shape[0 ...

  5. WD HC510 不能被识别

    折腾半天,终于记得去查官方文档

  6. 四、排序算法总结二(归并排序)(C++版本)

    一.什么是归并排序? 归并排序是基于分而治之的思想建立起来的. 所谓的分而治之,也就是将一个数据规模为N的数据集,分解为两个规模大小差不多的数据集(n/2),然而分别处理这两个更小的问题,就相当于解决 ...

  7. Java之匿名对象

    匿名对象概念 创建对象时,只有创建对象的语句,却没有把对象地址值赋值给某个变量.虽然是创建对象的简化写法,但是应用场景非常有限.匿名对象 :没有变量名的对象. 格式: new 类名(参数列表): // ...

  8. rsync的简介及使用

    1.rsync的基础概述 1.什么是备份 相当于给源文件增加一个副本,但是备份只会备份当前状态的数据,当你在写数据是,不会备份新写入的数据,除非自己手动在备份一次. 2.为什么要做备份 1.需要备份一 ...

  9. Codeforces Round #594 (Div. 1) D2. The World Is Just a Programming Task (Hard Version) 括号序列 思维

    D2. The World Is Just a Programming Task (Hard Version) This is a harder version of the problem. In ...

  10. 再一次生产 CPU 高负载排查实践

    前言 前几日早上打开邮箱收到一封监控报警邮件:某某 ip 服务器 CPU 负载较高,请研发尽快排查解决,发送时间正好是凌晨. 其实早在去年我也处理过类似的问题,并记录下来:<一次生产 CPU 1 ...