<main>
  <div id="animated">
    <div class="box"></div>
  </div>
  <input type="range" value="0" step="0.1" min="0" max="100">
</main>
:root {
  --theme-primary: var(--c-red);
  --theme-primary-rgb: var(--c-red-rgb);
  --theme-primary-hsl: var(--c-red-hsl);
  --theme-index: 0;
  --theme-length: 5;
  --border-radius: 3px;

  --c-red: #e9503c;
  --c-orange: #ff921b;
  --c-yellow: #ffc928;
  --c-green: #45d016;
  --c-teal: #64e7ff;
  --c-blue: #1b99ff;
  --c-purple: #8621d0;
  --c-red-rgb: 233, 80, 60;
  --c-orange-rgb: 255, 146, 27;
  --c-yellow-rgb: 255, 201, 40;
  --c-green-rgb: 69, 208, 22;
  --c-teal-rgb: 100, 231, 255;
  --c-blue-rgb: 27, 153, 255;
  --c-purple-rgb: 134, 33, 208;
  --c-red-hsl: 7, 80%, 57%;
  --c-orange-hsl: 31, 100%, 55%;
  --c-yellow-hsl: 45, 100%, 58%;
  --c-green-hsl: 105, 81%, 45%;
  --c-teal-hsl: 189, 100%, 70%;
  --c-blue-hsl: 207, 100%, 55%;
  --c-purple-hsl: 275, 73%, 47%;
  --ease-in-sine: cubic-bezier(0.47, 0, 0.745, 0.715);
  --ease-out-sine: cubic-bezier(0.39, 0.575, 0.565, 1);
  --ease-in-out-sine: cubic-bezier(0.445, 0.05, 0.55, 0.95);
  --ease-in-quad: cubic-bezier(0.55, 0.085, 0.68, 0.53);
  --ease-out-quad: cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --ease-in-out-quad: cubic-bezier(0.455, 0.03, 0.515, 0.955);
  --ease-in-cubic: cubic-bezier(0.55, 0.055, 0.675, 0.19);
  --ease-out-cubic: cubic-bezier(0.215, 0.61, 0.355, 1);
  --ease-in-out-cubic: cubic-bezier(0.645, 0.045, 0.355, 1);
  --ease-in-quart: cubic-bezier(0.895, 0.03, 0.685, 0.22);
  --ease-out-quart: cubic-bezier(0.165, 0.84, 0.44, 1);
  --ease-in-out-quart: cubic-bezier(0.77, 0, 0.175, 1);
  --ease-in-quint: cubic-bezier(0.755, 0.05, 0.855, 0.06);
  --ease-out-quint: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out-quint: cubic-bezier(0.86, 0, 0.07, 1);
  --ease-in-expo: cubic-bezier(0.95, 0.05, 0.795, 0.035);
  --ease-out-expo: cubic-bezier(0.19, 1, 0.22, 1);
  --ease-in-out-expo: cubic-bezier(1, 0, 0, 1);
  --ease-in-circ: cubic-bezier(0.6, 0.04, 0.98, 0.335);
  --ease-out-circ: cubic-bezier(0.075, 0.82, 0.165, 1);
  --ease-in-out-circ: cubic-bezier(0.785, 0.135, 0.15, 0.86);
  --ease-in-back: cubic-bezier(0.6, -0.28, 0.735, 0.045);
  --ease-out-back: cubic-bezier(0.175, 0.885, 0.32, 1.275);
  --ease-in-out-back: cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

#animated {
  --easing: linear;
  transform: rotate(0deg) translate(0, 0);
  transform-origin: 100% 100%;
  animation: box-roll 1s calc(var(--progress) * -1s) paused var(--easing) 1 both;
}

.box {
  animation: box-color 5s paused var(--easing) infinite both;
  animation-delay: calc(var(--progress, 0) * -5s + (var(--theme-index) * -1s));
  animation-duration: 5s;
  background: hsla(var(--theme-primary-hsl), 1);
}
@keyframes box-color {
  0% {
    background: hsla(var(--c-red-hsl), 1);
  }
  25% {
    background: hsla(var(--c-orange-hsl), 1);
  }
  25.01% {
    background: hsla(var(--c-yellow-hsl), 1);
  }
  50% {
    background: hsla(var(--c-green-hsl), 1);
  }
  50.01% {
    background: hsla(var(--c-teal-hsl), 1);
  }
  75% {
    background: hsla(var(--c-blue-hsl), 1);
  }
  75.01% {
    background: hsla(var(--c-purple-hsl), 1);
  }
  100% {
    background: hsla(var(--c-red-hsl), 1);
  }
}
@keyframes box-roll {
  0% {
    transform: rotate(0deg);
    transform-origin: 100% 100%;
  }
  25% {
    transform: rotate(90deg) translate(0, 0);
    transform-origin: 100% 100%;
  }
  25.01% {
    transform: rotate(0deg) translate(100%, 0);
    transform-origin: 200% 100%;
  }
  50% {
    transform: rotate(90deg) translate(100%, 0);
    transform-origin: 200% 100%;
  }
  50.01% {
    transform: rotate(0deg) translate(200%, 0);
    transform-origin: 300% 100%;
  }
  75% {
    transform: rotate(90deg) translate(200%, 0);
    transform-origin: 300% 100%;
  }
  75.01% {
    transform: rotate(0deg) translate(300%, 0);
    transform-origin: 400% 100%;
  }
  100% {
    transform: rotate(90deg) translate(300%, 0);
    transform-origin: 400% 100%;
  }
}
/* Demo styles */
* {
  box-sizing: border-box;
}
main {
  width: 100%;
  margin: 30px;
  margin-top: 100px;
  --box-size: 20%;
}
#animated {
  --size: var(--box-size);
  position: relative;
  width: var(--size);
  border-radius: var(--border-radius);
}
.box {
  display: block;
  width: 100%;
  padding-top: 100%;
}
input[type="range"] {
  margin-top: 15px;
  width: 100%;
}
const root = document.querySelector("main");
const input = root.querySelector("input");
const animated = root.querySelector("#animated");
input.addEventListener("input", (event) => {
  const min = Number(event.target.getAttribute("min"));
  const max = Number(event.target.getAttribute("max"));
  const value = Number(event.target.value);
  const progress = (value - min) / max;
  animated.style.setProperty("--progress", `${progress}`);
});
View Compiled

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.