Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's 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 it's URL and the proper URL extention.

+ 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

Save Automatically?

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="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;
}

              
            
!

JS

              
                import {
  SpringEasing,
  SpringOutFrame
} from "https://cdn.skypack.dev/spring-easing";

import gsap from "https://cdn.skypack.dev/gsap";
import anime from "https://cdn.skypack.dev/animejs";

import * as React from "https://cdn.skypack.dev/react";
import * as ReactDOM from "https://cdn.skypack.dev/react-dom";
import { motion } from "https://cdn.skypack.dev/framer-motion";

import { animate as motionone } from "https://cdn.skypack.dev/motion";
import { animate } from "https://cdn.skypack.dev/@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 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