<div id="anime-demo">
  <div class="line">
    <div class="square blue"></div>
    <div class="square red"></div>
    <div class="square blue"></div>
    <div class="square red"></div>
    <div class="square blue"></div>
  </div>
</div>
<div class="controls">
<button class="play-basic">Basic Timeline</button>
<button class="play-offset">Offset Timeline</button>
</div>
body {
  margin: 20px;
  font-family: 'Lato';
  font-weight: 300;
  font-size: 1.2em;
  text-align: center;
}

button {
  background: orange;
  color: white;
  margin: 5px;
  padding: 10px;
  border-radius: 4px;
  font-family: 'Lato';
  cursor: pointer;
  border: none;
  outline: none;
}

button:hover {
  background: blue;
}

.square {
  pointer-events: none;
  position: relative;
  width: 80px;
  height: 80px;
  background-color: black;
  margin: 16px;
  display: inline-block;
}

.red {
  background-color: red;
}

.blue {
  background-color: blue;
}

.controls {
  margin-top: 300px;
}
var basicTimeline = anime.timeline({
  direction: "alternate",
  loop: 2,
  autoplay: false
});

basicTimeline
  .add({
    targets: ".square",
    translateY: 200
  })
  .add({
    targets: ".red",
    translateY: 100
  })
  .add({
    targets: ".blue",
    translateY: 0
  });

var offsetTimeline = anime.timeline({
  direction: "alternate",
  loop: 2,
  autoplay: false
});

offsetTimeline
  .add({
    targets: ".square",
    translateY: 200
  })
  .add({
    targets: ".red",
    offset: "+=1000",
    translateY: 100
  })
  .add({
    targets: ".blue",
    offset: "*=2",
    translateY: 0
  });

document.querySelector(".play-basic").onclick = basicTimeline.restart;
document.querySelector(".play-offset").onclick = offsetTimeline.restart;

External CSS

  1. https://fonts.googleapis.com/css?family=Lato:300

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/animejs/2.0.2/anime.min.js