3.8 KiB
3.8 KiB
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
587d78a9367417b2b2512ae9 | Use a Bezier Curve to Move a Graphic | 0 | 使用贝塞尔曲线移动图形 |
Description
ease-out
关键字,该关键字描述了动画更改,该动画更改先加速,然后在动画结束时减慢。在右侧,演示了ease-out
关键字(对于蓝色元素)和linear
关键字(对于红色元素)之间的差异。通过使用自定义三次贝塞尔曲线函数,可以实现对ease-out
关键字的类似动画进展。通常,更改p1
和p2
锚点会驱动创建不同的贝塞尔曲线,这些曲线控制动画随时间推移的进展。下面是使用值来模拟缓出样式的贝塞尔曲线的示例: 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
red
的元素的animation-timing-function
更改为cubic-bezier
函数,其中x1,y1,x2,y2值分别设置为0,0,0.58,1这将使两个元素同样在动画中前进。 Tests
tests:
- text: 'id为<code>red</code>的元素的<code>animation-timing-function</code>属性值应为<code>cubic-bezier</code>函数,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 <code>animation-timing-function</code> property of the element with the id <code>red</code> should be a <code>cubic-bezier</code> function with x1, y1, x2, y2 values set respectively to 0, 0, 0.58, 1 .");'
- text: id为<code>red</code>的元素不应该具有linear的<code>animation-timing-function</code>属性。
testString: 'assert($("#red").css("animation-timing-function") !== "linear", "The element with the id <code>red</code> should no longer have the <code>animation-timing-function</code> property of linear.");'
- text: 具有id <code>blue</code>的元素的<code>animation-timing-function</code>属性的值不应更改。
testString: 'assert($("#blue").css("animation-timing-function") == "ease-out", "The value of the <code>animation-timing-function</code> property for the element with the id <code>blue</code> should not change.");'
Challenge Seed
<style>
.balls{
border-radius: 50%;
position: fixed;
width: 50px;
height: 50px;
margin-top: 50px;
animation-name: bounce;
animation-duration: 2s;
animation-iteration-count: infinite;
}
#red {
background: red;
left: 27%;
animation-timing-function: linear;
}
#blue {
background: blue;
left: 56%;
animation-timing-function: ease-out;
}
@keyframes bounce {
0% {
top: 0px;
}
100% {
top: 249px;
}
}
</style>
<div class="balls" id= "red"></div>
<div class="balls" id= "blue"></div>
Solution
// solution required