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

              
                <button id="loopControl">play/pause</button>
              
            
!

CSS

              
                body {
  display: flex;
  min-height: 100vh;
}

button {
  margin: auto;
}
              
            
!

JS

              
                /**
 * Given a value for hue in degrees, generate a set of steps to
 * transition the saturation and lightness values for that hue.
 *
 * THIS IS COMPLETELY ARBITRARY, need to just eyeball it and add/remove
 * definitions until it kinda looks ok. Can also add timings for each
 * in attempt to make it look nicer/smoother.
 */
const slTransition = (hue) => [
  { backgroundColor: `hsl(${hue}, 100%, 50%)`},
  { backgroundColor: `hsl(${hue}, 50%, 100%)`},
  { backgroundColor: `hsl(${hue}, 0%, 50%)`},
  { backgroundColor: `hsl(${hue}, 50%, 100%)`},
  { backgroundColor: `hsl(${hue}, 100%, 50%)`},
];

/**
 * The animations API expects an array of transition objects, so
 * produce and array of the hue values [numbers] 0 to 359, and for
 * each of those, map using the `slTransition` function to give
 * all transitions for all hues.
 */
const transitions = Array.from({length: 360 }, (_, i) => i).flatMap(slTransition);

/**
 * There are 360 hue steps, and each step has however many steps are defined
 * in the `slTransition` function. If all of those steps have the same timing,
 * then can just multiply by some arbitrary number of milliseconds for simplicity.
 */
const STEP_DURATION = 500;
const timing = {
  duration: 360 * 5 * STEP_DURATION,
  iterations: Infinity
};

// Keep a reference to the animation so can pause/play
const loop = document.body.animate(transitions, timing);
// It will always start automatically, so pause it immediately
loop.pause();

const loopControl = document.querySelector("#loopControl");

loopControl.addEventListener("click", () => {
  if (loop.playState === "paused") {
    loop.play();
    loopControl.innerText = "pause";
  } else {
    loop.pause();
    loopControl.innerText = "play";
  }
});

  






              
            
!
999px

Console