--- id: 587d78a9367417b2b2512ae9 title: Use a Bezier Curve to Move a Graphic challengeType: 0 videoUrl: '' localeTitle: 使用贝塞尔曲线移动图形 --- ## Description
之前的挑战讨论了一个ease-out关键字,该关键字描述了动画更改,该动画更改先加速,然后在动画结束时减慢。在右侧,演示了ease-out关键字(对于蓝色元素)和linear关键字(对于红色元素)之间的差异。通过使用自定义三次贝塞尔曲线函数,可以实现对ease-out关键字的类似动画进展。通常,更改p1p2锚点会驱动创建不同的贝塞尔曲线,这些曲线控制动画随时间推移的进展。下面是使用值来模拟缓出样式的贝塞尔曲线的示例: animation-timing-function: cubic-bezier(0, 0, 0.58, 1);请记住,所有cubic-bezier函数都以(0,0)处的p0开始,并以(1,1)处的p3结束。在这个例子中,曲线移动通过Y轴(从0开始,到p1 y值为0,然后到p2 y值为1)比在X轴上移动更快(0开始,然后是0对于p1 ,对于p2 ,高达0.58)。结果,动画元素的变化比该段的动画时间更快。接近曲线的末端,x和y值的变化之间的关系反转 - y值从1移动到1(无变化),x值从0.58移动到1,使得动画变化进展比较慢动画持续时间。
## Instructions
要查看此贝塞尔曲线的效果,请将id为red的元素的animation-timing-function更改为cubic-bezier函数,其中x1,y1,x2,y2值分别设置为0,0,0.58,1这将使两个元素同样在动画中前进。
## Tests
```yml tests: - text: 'id为red的元素的animation-timing-function属性值应为cubic-bezier函数,x1,y1,x2,y2值分别设置为0,0,0.58,1。' testString: 'assert($("#red").css("animation-timing-function") == "cubic-bezier(0, 0, 0.58, 1)", "The value of the animation-timing-function property of the element with the id red should be a cubic-bezier function with x1, y1, x2, y2 values set respectively to 0, 0, 0.58, 1 .");' - text: id为red的元素不应该具有linear的animation-timing-function属性。 testString: 'assert($("#red").css("animation-timing-function") !== "linear", "The element with the id red should no longer have the animation-timing-function property of linear.");' - text: 具有id blue的元素的animation-timing-function属性的值不应更改。 testString: 'assert($("#blue").css("animation-timing-function") == "ease-out", "The value of the animation-timing-function property for the element with the id blue should not change.");' ```
## Challenge Seed
```html
```
## Solution
```js // solution required ```