freeCodeCamp/curriculum/challenges/chinese/01-responsive-web-design/applied-visual-design/learn-how-bezier-curves-wor...

3.6 KiB
Raw Blame History

id title challengeType videoUrl localeTitle
587d78a9367417b2b2512ae8 Learn How Bezier Curves Work 0 了解Bezier曲线的工作原理

Description

最后一项挑战引入了animation-timing-function属性和一些在其持续时间内改变动画速度的关键字。 CSS提供了除关键字之外的选项通过使用贝塞尔曲线可以更好地控制动画的播放方式。在CSS动画中贝塞尔曲线与cubic-bezier函数一起使用。曲线的形状表示动画的播放方式。曲线位于1乘1坐标系上。此坐标系的X轴是动画的持续时间将其视为时间刻度Y轴是动画中的变化。 cubic-bezier函数由四个主要点组成这些点位于1 x 1网格上 p0 p1 p2p3 。为您设置p0p3 - 它们是始终分别位于原点0,01,1的起点和终点。您可以为其他两个点设置x和y值并将它们放置在网格中的位置决定了要遵循的动画曲线的形状。这是在CSS中通过以下形式声明p1p2 “锚”点的x和y值来完成的 (x1, y1, x2, y2) 。将它们全部拉到一起这里是CSS代码中Bezier曲线的一个例子 animation-timing-function: cubic-bezier(0.25, 0.25, 0.75, 0.75);在上面的示例中x和y值对于每个点都是等效的x1 = 0.25 = y1和x2 = 0.75 = y2如果您记得几何类则会产生从原点延伸到点的线1 1。此动画是动画长度期间元素的线性变化与使用linear关键字相同。换句话说,它以恒定的速度变化。

Instructions

对于id为ball1的元素,将animation-timing-function属性的值从linear更改为其等效的cubic-bezier函数值。使用上面示例中给出的点值。

Tests

tests:
  - text: 具有id <code>ball1</code>的元素的<code>animation-timing-function</code>属性的值应该是线性等效的cubic-bezier函数。
    testString: 'assert($("#ball1").css("animation-timing-function") == "cubic-bezier(0.25, 0.25, 0.75, 0.75)", "The value of the <code>animation-timing-function</code> property for the element with the id <code>ball1</code> should be the linear-equivalent cubic-bezier function.");'
  - text: 具有id <code>ball2</code>的元素的<code>animation-timing-function</code>属性的<code>ball2</code>不应更改。
    testString: 'assert($("#ball2").css("animation-timing-function") == "ease-out", "The value of the <code>animation-timing-function</code> property for the element with the id <code>ball2</code> should not change.");'

Challenge Seed

<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: linear;
  }
  #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>

Solution

// solution required