freeCodeCamp/curriculum/challenges/chinese/01-responsive-web-design/applied-visual-design/use-a-bezier-curve-to-move-...

3.8 KiB
Raw Blame History

id title challengeType videoUrl localeTitle
587d78a9367417b2b2512ae9 Use a Bezier Curve to Move a Graphic 0 使用贝塞尔曲线移动图形

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函数其中x1y1x2y2值分别设置为0,0,0.58,1这将使两个元素同样在动画中前进。

Tests

tests:
  - text: 'id为<code>red</code>的元素的<code>animation-timing-function</code>属性值应为<code>cubic-bezier</code>函数x1y1x2y2值分别设置为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