Как сделать многоступенчатую простую анимацию в CSS? - PullRequest
0 голосов
/ 15 сентября 2018

Я хочу реализовать следующую анимацию с использованием CSS в центре экрана:

  1. текст "Hello" исчезает
  2. текст "Hello" исчезает
  3. появляется маленький кружок и превращается в большой прямоугольник

Я реализовал третий шаг следующим образом:

.step3 {
  height: 250px;
  width: 250px;
  margin: 0 auto;
  background-color: blue;
  animation-name: stretch;
  animation-duration: 10s;
  animation-timing-function: ease-out;
  animation-delay: 0;
  animation-direction: alternate;
  animation-iteration-count: 1;
  animation-fill-mode: none;
  animation-play-state: running;
}

@keyframes stretch {
  0% {
    transform: scale(.3);
    border-radius: 100%;
  }
  100% {
    transform: scale(1.5);
  }
}
<div class="step3"></div>

Я читал о animate.css, который можно использовать для увеличения и уменьшения текста:

<div class="animated fadeIn 1">Hello</div>

Но как я могуисчезать этот текст последовательно?И как я могу поместить все 3 шага в последовательность?

Ответы [ 2 ]

0 голосов
/ 15 сентября 2018

Вы можете сделать что-то подобное, если я вас правильно понимаю:

body {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0;
  height: 100vh;
}

.step3 {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 250px;
  width: 250px;
  border-radius: 50%;
  animation: stretch 10s 3s ease-out forwards;
}

.step3 > span {
  opacity: 0;
  animation: fadeInOut 3s;
}

@keyframes stretch {
  0%, 100% {transform: scale(.3); background: blue}
  100% {
    transform: scale(1.5);
    border-radius: 0;
  }
}

@keyframes fadeInOut {
  50% {opacity: 1}
  100% {opacity: 0}
}
<div class="step3"><span>Hello</span></div>
0 голосов
/ 15 сентября 2018

вам нужно прочитать о двух свойствах здесь 1. задержка анимации 2. режим заливки анимации

Задержка анимации приведет к тому, что анимация запустится через некоторое время, поэтому в основном вы можете запустить вторую анимацию после окончания первой

Режим заливки анимации вы можете прочитать здесь https://developer.mozilla.org/en-US/docs/Web/CSS/animation-fill-mode

div {
  position: absolute;
  
}

body {
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items:center;
  justify-content: center;
}

.text{
  font-size: 3em;
  /*animation: showfade 4s linear 2s both;*/
  animation-name: showfade;
  animation-duration: 4s;
  animation-delay: .4s;
  animation-fill-mode: both;
  
}

.rect {
  
  background-color: #07f;
  width: 200px;
  height: 200px;
  /*animation: rect 2s  linear 6s both;*/
  animation-name: rect;
  animation-duration: 2s;
  animation-delay: 4.4s;
  animation-fill-mode: both;
}


@keyframes showfade {
  0%, 100% {
    opacity: 0;
    
  }
  
  50% {
    opacity: 100;
  }
}

@keyframes rect {
  from {
    transform: scale(0);
    border-radius: 100%;
  }
}
<div class="text">Hello</div>
<div class="rect"></div>
...