Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>spring-easing - demo</h1>

<div class="linear-easing-css">
  <h2>Linear Easing CSS</h2>
  <div class="box"></div>
</div>

<div class="linear-easing-waapi">
  <h2>Linear Easing WAAPI</h2>
  <div class="box"></div>
</div>

<div class="gsap">
  <h2>gsap</h2>
  <div class="box"></div>
</div>

<div class="animejs">
  <h2>animejs</h2>
  <div class="box"></div>
</div>

<div class="waapi">
  <h2>Web Animation API (WAAPI)</h2>
  <div class="box"></div>
</div>

<div class="framer-motion">
  <h2>framer motion</h2>
  <div id="root"></div>
</div>

<div class="motion-one">
  <h2>motion one</h2>
  <div class="box"></div>
</div>

<div class="okikio_animate">
  <h2>@okikio/animate</h2>
  <div class="box"></div>
</div>
              
            
!

CSS

              
                :root {
  color-scheme: dark light;
}

body {
  padding: 56px;
  display: flex;
  flex-direction: column;
  gap-y: 2rem;
}

.box {
  width: 70px;
  height: 70px;
  border-radius: 12px;
  background: lightcoral;
}

.linear-easing-css .box {
  animation: move infinite alternate;
  animation-duration: var(--spring-duration);
  animation-timing-function: var(--spring-easing);
  animation-play-state: paused;
}

@keyframes move {
  from {
    translate: 0;
    rotate: 0;
  }
  to {
    translate: 250px;
    rotate: 360deg;
  }
}

              
            
!

JS

              
                import {
  SpringEasing,
  CSSSpringEasing,
  SpringOutFrame
} from "https://esm.sh/spring-easing";

import gsap from "https://esm.sh/gsap";
import anime from "https://esm.sh/animejs";

import * as React from "https://esm.sh/react";
import * as ReactDOM from "https://esm.sh/react-dom";
import { motion } from "https://esm.sh/framer-motion";

import { animate as motionone } from "https://esm.sh/motion";
import { animate } from "https://esm.sh/@okikio/animate";

// Note: this is the return value of {@link SpringEasing} and {@link GenerateSpringFrames}, you don't need the object to get this format
let [translateX, duration] = SpringEasing([0, 250], {
  easing: "spring-out(1, 100, 10, 0)",
  // You can change the size of Array for the SpringEasing function to generate
  numPoints: 200,
  // The number of decimal places to round, final values in the generated Array
  // This option doesn't exist on {@link GenerateSpringFrames}
  decimal: 5
});

// Round the duration manually, to fix bug with different animation libraries rounding the duration differently
duration = Math.round(duration);

// Rotate
let [rotate] = SpringEasing([0, 360], {
  easing: [SpringOutFrame, 1, 100, 10, 0],

  // You can change the size of Array for the SpringEasing function to generate
  numPoints: 200
});

let [easings] = CSSSpringEasing({
  easing: [SpringOutFrame, 1, 100, 10, 0],

  // You can change the size of Array for the SpringEasing function to generate
  numPoints: 200
});

const cssLinearEasingBox = document.querySelector(".linear-easing-css .box");
cssLinearEasingBox.style.setProperty("--spring-duration", `${duration}ms`);
cssLinearEasingBox.style.setProperty("--spring-easing", `linear(${easings})`);
cssLinearEasingBox.style.setProperty("animation-play-state", "running");

// Not all browsers support linear(...) easing yet
try {
  document.querySelector(".linear-easing-waapi .box").animate(
    {
      translate: ["0", "250px"],
      rotate: ["0", "360deg"]
    },
    {
      // TIP... Use linear easing for the proper effect
      easing: `linear(${easings})`,

      // The optimal duration for this specific spring
      duration,

      iterations: Infinity,
      direction: "alternate"
    }
  );
} catch (e) {
  console.warn(e.toString());
}

let wrappedX = gsap.utils.wrap(translateX);
let wrappedRotate = gsap.utils.wrap(rotate);
gsap.fromTo(
  ".gsap .box",
  { x: 0, rotation: 0 },
  {
    duration: duration / 1000,
    ease: "none",
    x: translateX.length,
    rotation: rotate.length,
    modifiers: {
      x: (x) => wrappedX(parseFloat(x)) + "px",
      rotation: (x) => wrappedRotate(parseFloat(x)) + "deg"
    },
    yoyo: true,
    repeat: -1
  }
);

anime({
  targets: ".animejs .box",

  // Using spring easing animate from [0 to 250] using `spring-out-in`
  translateX,
  // You can set the easing without an object
  rotate,
  // TIP... Use linear easing for the proper effect
  easing: "linear",

  // The optimal duration for this specific spring
  duration,

  loop: true,
  direction: "alternate"
});

let transform = rotate.map(
  (x, i) => `translateX(${translateX[i]}px) rotate(${rotate[i]}deg)`
);

document.querySelector(".waapi .box").animate(
  {
    transform
  },
  {
    // TIP... Use linear easing for the proper effect
    easing: "linear",

    // The optimal duration for this specific spring
    duration,

    iterations: Infinity,
    direction: "alternate"
  }
);

function Box() {
  return (
    <motion.div
      className="box"
      animate={{
        x: translateX,
        rotate
      }}
      transition={{
        // TIP... Use linear easing for the proper effect
        easing: "linear",
        duration: duration / 1000,

        repeat: Infinity,
        repeatType: "reverse"
      }}
    ></motion.div>
  );
}

ReactDOM.render(<Box />, document.querySelector(".framer-motion #root"));

motionone(
  document.querySelector(".motion-one .box"),
  {
    transform
  },
  {
    // TIP... Use linear easing for the proper effect
    easing: "linear",

    // The optimal duration for this specific spring
    duration: duration / 1000,

    repeat: Infinity,
    direction: "alternate"
  }
);

animate({
  targets: ".okikio_animate .box",

  // Using spring easing animate from [0 to 250] using `spring-out-in`
  translateX,
  // You can set the easing without an object
  rotate,
  // TIP... Use linear easing for the proper effect
  easing: "linear",

  // The optimal duration for this specific spring
  duration,

  loop: true,
  direction: "alternate"
});

              
            
!
999px

Console