Files
2022-01-20 20:30:18 +01:00

3.1 KiB

id, title, challengeType, videoUrl, forumTopicId, dashedName
id title challengeType videoUrl forumTopicId dashedName
587d78a7367417b2b2512ae1 CSS アニメーションを使って動きを作る 0 https://scrimba.com/c/c7amZfW 301051 create-movement-using-css-animation

--description--

要素に fixedrelative のような position が指定されているとき、CSS オフセットプロパティ rightlefttopbottom を使ってアニメーションのルールで動きを付けることができます。

下記の例のように、50% のキーフレームで top プロパティを 50px に設定し、最初 (0%) と最後 (100%) のキーフレームでは 0px を設定することで、要素を上下に動かすことができます。

@keyframes rainbow {
  0% {
    background-color: blue;
    top: 0px;
  }
  50% {
    background-color: green;
    top: 50px;
  }
  100% {
    background-color: yellow;
    top: 0px;
  }
}

--instructions--

div のアニメーションに水平方向の動きを追加しましょう。 @keyframes ルールに left オフセットプロパティを追加し、rainbow のアニメーションが 0% で 0 ピクセルから始まり、50% で 25 ピクセルになり、100% で -25 ピクセルで終わるようにしてください。 エディタにある top プロパティは書き換えないようにしてください。アニメーションは垂直方向と水平方向両方の動きを持つ必要があります。

--hints--

0%@keyframes ルールは、left オフセットが 0px である必要があります。

assert(code.match(/[^50]0%\s*?{[\s\S]*?left:\s*?0px(;[\s\S]*?|\s*?)}/gi));

50%@keyframes ルールは、left オフセットが 25px である必要があります。

assert(code.match(/50%\s*?{[\s\S]*?left:\s*?25px(;[\s\S]*?|\s*?)}/gi));

100%@keyframes ルールは、left オフセットが -25px である必要があります。

assert(code.match(/100%\s*?{[\s\S]*?left:\s*?-25px(;[\s\S]*?|\s*?)}/gi));

--seed--

--seed-contents--

<style>
  div {
    height: 40px;
    width: 70%;
    background: black;
    margin: 50px auto;
    border-radius: 5px;
    position: relative;
  }

  #rect {
    animation-name: rainbow;
    animation-duration: 4s;
  }

  @keyframes rainbow {
    0% {
      background-color: blue;
      top: 0px;

    }
    50% {
      background-color: green;
      top: 50px;

    }
    100% {
      background-color: yellow;
      top: 0px;

    }
  }
</style>

<div id="rect"></div>

--solutions--

<style>
  div {
    height: 40px;
    width: 70%;
    background: black;
    margin: 50px auto;
    border-radius: 5px;
    position: relative;
  }

  #rect {
    animation-name: rainbow;
    animation-duration: 4s;
  }

  @keyframes rainbow {
    0% {
      background-color: blue;
      top: 0px;
      left: 0px;
    }
    50% {
      background-color: green;
      top: 50px;
      left: 25px;
    }
    100% {
      background-color: yellow;
      top: 0px;
      left: -25px;
    }
  }
</style>
<div id="rect"></div>