<div class="demoBody">
<div id="sequence" class="timelineDemo">


     <div class="box green" data-color="#28a92b" id="green"></div>
    <div class="box purple" data-color="#8d3dae" id="purple"></div>
    <div class="box orange" data-color="#e77614" id="orange"></div>


    <div class="timelineUI">
      <div class="timelineUI-time" id="sequenceTime">0</div>
      <div class="timelineUI-dragger-track">
        <div class="timelineUI-dragger">
          <div></div>
        </div>
      </div>
      <div class="markers">
      </div>

      <div class="timleineUI-row">
        <div class="timelineUI-tween green"></div>
      </div>
      <div class="timleineUI-row">
        <div class="timelineUI-tween purple"></div>
      </div>
      <div class="timleineUI-row">
        <div class="timelineUI-tween orange"></div>
      </div>
    </div>
    <div class="controls">
      <button class="timelineUI-button play">play</button>
    </div>
  </div>
</div>

body {
  background-color: #fafafa;
  overflow: hidden;
  margin: 0;
  padding: 0;
}

.content .demoBody code.prettyprint,
.content .demoBody pre.prettyprint {
  margin: 0;
}
.content .demoBody pre.prettyprint {
  width: auto;
}
.content .demoBody code,
.main-content .demoBody code {
  background-color: transparent;
  font-size: 18px;
  line-height: 22px;
}
.demoBody {
  background-color: #1d1d1d;
  font-family: "Signika Negative", sans-serif;
  color: #989898;
  font-size: 16px;
  width: 100%;
  margin: auto;
  border-radius: 15px;
}

.timelineDemo {
  margin: auto;
  background-color: #1d1d1d;
  width: 80%;
  padding: 20px 0;
}

.demoBody h1,
.demoBody h2,
.demoBody h3 {
  margin: 10px 0 10px 0;
  color: #f3f2ef;
}

.demoBody h1 {
  font-size: 36px;
}

.demoBody h2 {
  font-size: 18px;
  font-weight: 300;
}

.demoBody h3 {
  font-size: 24px;
}

.demoBody p {
  line-height: 22px;
  margin-bottom: 16px;
  width: 80%;
}

.timelineDemo .box {
  width: 50px;
  height: 50px;
  position: relative;
  border-radius: 6px;
  margin-bottom: 4px;
}

.timelineDemo .green {
  background-color: #28a92b;
}

.timelineDemo .orange {
  background-color: #e77614;
}
.timelineDemo .purple {
  background-color: #8d3dae;
}

.timleineUI-row {
  background-color: #2f2f2f;
  margin: 2px 0;
  padding: 4px 0;
}

.markers {
  display: flex;
  width: 100%;
  align-items: space-apart;
  justify-content: space-between;
}

.secondMarker {
  border-left: solid 1px #aaa;
  height: 10px;
  display: inline-block;
  position: relative;
  line-height: 16px;
  font-size: 16px;
  color: #777;
}

.timelineUI-tween {
  position: relative;
  width: 20%;
  height: 16px;
  border-radius: 8px;
}

.timelineUI-tween.green {
  width: 40%;
}

.timelineUI-dragger-track {
  position: relative;
  width: 100%;
  margin-top: 20px;
}

.timelineUI-dragger {
  position: absolute;
  width: 10px;
  height: 100px;
  top: -25px;
}

.timelineUI-dragger div {
  position: relative;
  width: 20px;
  height: 20px;
  background-color: #e74d4d;
  left: -10px;
  border-radius: 99px;
}

.timelineUI-dragger div::after {
  content: " ";
  position: absolute;
  width: 1px;
  height: 95px;
  top: 100%;
  left: calc(50% - 1px);
  border-left: solid 2px #e74d4d;
}

.timelineUI-dragger div::before {
  content: " ";
  position: absolute;
  width: 20px;
  height: 114px;
  top: -20px;
  left: -10px;
}

.timelineUI-time {
  position: relative;
  font-size: 30px;
  text-align: center;
}

.controls {
  margin: 10px 2px;
}

.prettyprint {
  font-size: 20px;
  line-height: 24px;
}

.timelineUI-button {
  background: #414141;
  background-image: -webkit-linear-gradient(top, #575757, #414141);
  background-image: -moz-linear-gradient(top, #575757, #414141);
  background-image: -ms-linear-gradient(top, #575757, #414141);
  background-image: -o-linear-gradient(top, #575757, #414141);
  background-image: linear-gradient(to bottom, #575757, #414141);
  text-shadow: 0px 1px 0px #414141;
  -webkit-box-shadow: 0px 1px 0px 414141;
  -moz-box-shadow: 0px 1px 0px 414141;
  box-shadow: 0px 1px 0px 414141;
  color: #ffffff;
  text-decoration: none;
  margin: 0 auto;
  -webkit-border-radius: 4;
  -moz-border-radius: 4;
  border-radius: 4px;
  font-family: "Signika Negative", sans-serif;
  text-transform: uppercase;
  font-weight: 600;
  display: table;
  cursor: pointer;
  font-size: 13px;
  line-height: 18px;
  outline: none;
  border: none;
  display: inline-block;
  padding: 8px 14px;
}

.timelineUI-button:hover {
  background: #57a818;
  background-image: -webkit-linear-gradient(top, #57a818, #4d9916);
  background-image: -moz-linear-gradient(top, #57a818, #4d9916);
  background-image: -ms-linear-gradient(top, #57a818, #4d9916);
  background-image: -o-linear-gradient(top, #57a818, #4d9916);
  background-image: linear-gradient(to bottom, #57a818, #4d9916);
  text-shadow: 0px 1px 0px #32610e;
  -webkit-box-shadow: 0px 1px 0px fefefe;
  -moz-box-shadow: 0px 1px 0px fefefe;
  box-shadow: 0px 1px 0px fefefe;
  color: #ffffff;
  text-decoration: none;
}

.element-box {
  background: #ffffff;
  border-radius: 6px;
  border: 1px solid #cccccc;
  padding: 17px 26px 17px 26px;
  font-weight: 400;
  font-size: 18px;
  color: #555555;
  margin-bottom: 20px;
}

.demoBody .prettyprint {
  min-width: 300px;
}

.boxes {
  display: flex;
  justify-content: space-around;
}
let width = document.querySelector('.timelineUI').offsetWidth

let tl = gsap.timeline({ onUpdate: sequenceUpdateDragger, paused: true });

tl
  .to("#sequence #green", { x: 600, duration: 2 })
  .to("#sequence #purple", { x: 600, duration: 1, delay: 1 })
  .to("#sequence #orange", { x: 600, duration: 1 });


gsap.to('.timelineUI-tween', {opacity: 1})
let sequenceTime = $("#sequenceTime");
let markerCont = document.querySelector(".markers");
markerCont.innerHTML = '';
let sequenceTrackLength = width;
let sequenceDragger = $("#sequence .timelineUI-dragger");
let timelineItems = document.querySelectorAll(".timelineUI-tween");
let children = tl.getChildren();
let time = tl.duration();

for (let i = 0; i < time + 1; i++) {
  markerCont.innerHTML += `<div class="secondMarker"></div>`;
}

function sequenceUpdateDragger() {
  gsap.set(sequenceDragger, {
    x: sequenceTrackLength * tl.progress()
  });
  sequenceTime.html(tl.time().toFixed(2));
}

let sequenceDraggable = new Draggable(sequenceDragger, {
  type: "x",
  bounds: { minX: 0, maxX: sequenceTrackLength },
  trigger: "#sequence .timelineUI-dragger div",
  onDrag: function () {
    tl.progress(this.x / sequenceTrackLength).pause();
  }
})[0];

children.forEach((child, index) => {
	let timelineBar = timelineItems[index];
	let duration = child.duration();
	let startTime = child.startTime();
	let width = (duration / time) * 100;
	let startPosition = (startTime / time) * 100;
	let color = child._targets[0].dataset.color;

	gsap.set(timelineBar, {
		width: `${width}%`,
		marginLeft: `${startPosition}%`,
		backgroundColor: color
	});
});

$("#sequence .play").click(function () {
  if (tl.progress() < 1) {
    tl.play();
  } else {
    tl.restart();
  }
});

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. //cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js
  2. https://unpkg.co/gsap@3/dist/gsap.min.js
  3. https://unpkg.com/gsap@3/dist/Draggable.min.js
  4. //cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js