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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <div id="app"></div>
              
            
!

CSS

              
                body, html {
  height: 100%;
}
* {
  box-sizing: border-box;
}
#app {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 0 4rem;
}

.screen {
  width: 320px;
  height: 320px;
  flex-shrink: 0;
  overflow: hidden;
  box-shadow: 0px 10px 30px hsl(0, 0%, 95%), 0px 3px 4px hsl(0, 0%, 85%);
  position: relative;
  display: flex;
  align-items: center;
  border-radius: 160px;
}

.reel {
  position: absolute;
  height: 241px;
  left: 0;
}

.projector {
  width: 100%;
  max-width: 320px;
}

p {
  margin: 1.25em 0 0.75em 0;
  font-weight: bold;
  padding: 0;
  line-height: 1;
  font-family: arial;
}

input[type=range] {
  -webkit-appearance: none; /* Hides the slider so that custom slider can be made */
  width: 100%; /* Specific width is required for Firefox. */
  background: transparent; /* Otherwise white in Chrome */
}

input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
}

input[type=range]:focus {
  outline: none; /* Removes the blue border. You should probably do some kind of focus styling for accessibility reasons though. */
}

input[type=range]::-ms-track {
  width: 100%;
  cursor: pointer;

  /* Hides the slider so custom styles can be added */
  background: transparent; 
  border-color: transparent;
  color: transparent;
}

/* Special styling for WebKit/Blink */
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  height: 16px;
  width: 16px;
  border-radius: 8px;
  background: hsl(195, 90%, 50%);
  cursor: pointer;
  margin-top: -6px; /* You need to specify a margin in Chrome, but in Firefox and IE it is automatic */
  box-shadow: 0px 0px 2px rgba(black, 0.5);
}

/* All the same stuff for Firefox */
input[type=range]::-moz-range-thumb {
  -webkit-appearance: none;
  height: 16px;
  width: 16px;
  border-radius: 8px;
  background: hsl(195, 90%, 50%);
  cursor: pointer;
  margin-top: -6px; /* You need to specify a margin in Chrome, but in Firefox and IE it is automatic */
  box-shadow: 0px 0px 2px rgba(black, 0.5);
}

/* All the same stuff for IE */
input[type=range]::-ms-thumb {
  -webkit-appearance: none;
  height: 16px;
  width: 16px;
  border-radius: 8px;
  background: hsl(195, 90%, 50%);
  cursor: pointer;
  margin-top: -6px; /* You need to specify a margin in Chrome, but in Firefox and IE it is automatic */
  box-shadow: 0px 0px 2px rgba(black, 0.5);
}

input[type=range]::-webkit-slider-runnable-track {
  width: 100%;
  height: 3px;
  cursor: pointer;
  background: hsl(195, 30%, 70%);
  border-radius: 1.3px;
}

input[type=range]:focus::-webkit-slider-runnable-track {
  background: #367ebd;
}

input[type=range]::-moz-range-track {
  width: 100%;
  height: 3px;
  cursor: pointer;
  background: hsl(195, 30%, 70%);
  border-radius: 1.3px;
}

input[type=range]::-ms-track {
  width: 100%;
  height: 3px;
  cursor: pointer;
  background: hsl(195, 30%, 70%);
  border-radius: 1.3px;
}
input[type=range]::-ms-fill-lower {
  width: 100%;
  height: 3px;
  cursor: pointer;
  background: hsl(195, 30%, 70%);
  border-radius: 1.3px;
}
input[type=range]:focus::-ms-fill-lower {
  background: #3071a9;
}
input[type=range]::-ms-fill-upper {
  width: 100%;
  height: 3px;
  cursor: pointer;
  background: hsl(195, 30%, 70%);
  border-radius: 1.3px;
}
input[type=range]:focus::-ms-fill-upper {
  background: hsl(195, 30%, 70%);
}

              
            
!

JS

              
                const { useState, useEffect } = React;

const Reel = ({ speed }) => {
  
  const [left, setLeft] = useState(0);
  
  useEffect(() => {
    let counter = setInterval(() => {
      setLeft(prevLeft => {
        if (prevLeft <= (2880 - (320 + speed)) * -1) {
          return 0;
        }
        return prevLeft - speed;
      });
    }, 41.6667);
    return () => clearInterval(counter);
  });

  return (
    <img
      className="reel"
      src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1376484/frames_v2.jpg"
      alt="🎠"
      style={{ left }}
    />
  );
};

const App = () => {
  const [speed, setSpeed] = useState(2);
  const [msg, setMsg] = useState("Fix the broken projector");
  handleSpeed = e => {
    let val = parseInt(e.target.value);
    setSpeed(val);
    if (val >= 45 && val <= 55 && val != 50) {
      setMsg("Animations trick our brain into seeing two speeds");
    } else if (val == 50) {
      setMsg("Perfect!");
    } else {
      setMsg("Fix the broken projector");
    }
  };

  return (
    <>
      <div className="screen">
        <Reel speed={speed * 6.4} />
      </div>
      <p>{msg}</p>
      <input
        onInput={handleSpeed}
        value={speed}
        type="range"
        className="projector"
      />
    </>
  );
};

// Render app
ReactDOM.render(<App />, document.getElementById("app"));

              
            
!
999px

Console