Files
freeCodeCamp/curriculum/challenges/russian/01-responsive-web-design/applied-visual-design/create-movement-using-css-animation.russian.md

4.0 KiB
Raw Blame History

id, title, challengeType, videoUrl, forumTopicId, localeTitle
id title challengeType videoUrl forumTopicId localeTitle
587d78a7367417b2b2512ae1 Create Movement Using CSS Animation 0 https://scrimba.com/c/c7amZfW 301051 Создание движения с использованием анимации CSS

Description

Когда элементы имеют заданную position , например fixed или relative , свойства смещения CSS right , left , top и bottom могут использоваться в правилах анимации для создания движения. Как показано в приведенном ниже примере, вы можете нажать элемент вниз, а затем вверх, установив top свойство 50% ключевого кадра на 50% пикселей, но установив его на 0px для первого ( 0% ) и последнего ( 100% ) ключевого кадра.
@keyframes rainbow {
0% {
background-color: blue;
top: 0px;
}
50% {
фон-цвет: зеленый;
top: 50px;
}
100% {
background-color: желтый;
top: 0px;
}
}

Instructions

Добавьте горизонтальное движение в анимацию div . Используя свойство left offset, добавьте правило @keyframes так что радуга начинается с 0 пикселей на 0% , перемещается до 25 пикселей с 50% и заканчивается на -25 пикселей при 100% . Не заменяйте top свойство в редакторе - анимация должна иметь как вертикальное, так и горизонтальное движение.

Tests

tests:
  - text: The <code>@keyframes</code> rule for <code>0%</code> should use the <code>left</code> offset of 0px.
    testString: assert(code.match(/0%\s*?{\s*?background-color:\s*?blue;\s*?top:\s*?0(px)?;\s*?left:\s*?0(px)?;\s*?}/gi));
  - text: The <code>@keyframes</code> rule for <code>50%</code> should use the <code>left</code> offset of 25px.
    testString: assert(code.match(/50%\s*?{\s*?background-color:\s*?green;\s*?top:\s*?50px;\s*?left:\s*?25px;\s*?}/gi));
  - text: The <code>@keyframes</code> rule for <code>100%</code> should use the <code>left</code> offset of -25px.
    testString: assert(code.match(/100%\s*?{\s*?background-color:\s*?yellow;\s*?top:\s*?0(px)?;\s*?left:\s*?-25px;\s*?}/gi));

Challenge Seed

<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>

Solution

<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>