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

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

CSS

              
                $blur: 4px;

html, body {
  padding: 0;
  margin: 0;
  height: 100%;
}
#root {
  height: 100%;
}
.page {
  height: 100%;
  position: relative;
  overflow: hidden;
  background-attachment: fixed;
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  &:not(:first-of-type) {
    &:before {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      box-shadow: inset 0 2px black, inset 0 10px 10px rgba(black, 0.8);;
      z-index: 100;
    }
  }
  .static {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    .centered {
      background: black;
      padding: 50px 100px 70px;
      overflow: hidden;
      position: relative;
      width: 100%;
      box-shadow: 0 0 0 1px rgba(black, 0.4), 0 5px 10px rgba(black, 0.6);
      .bg {
        position: absolute;
        top: 0;
        right: -50px;
        bottom: 0;
        left: -50px;
        background-position: center;
        background-size: cover;
        background-repeat: no-repeat;
        z-index: 0;
        filter: blur($blur);
        opacity: 0.65;
      }
      h1 {
        font-family: 'Segoe UI', HelveticaNeue, sans-serif;
        font-size: 60px;
        font-weight: lighter;
        color: white;
        text-align: center;
        margin: 0;
        position: relative;
      }
      h2 {
        font-family: 'Segoe UI', HelveticaNeue, sans-serif;
        font-size: 20px;
        font-weight: lighter;
        color: white;
        text-align: center;
        margin: 0;
        text-transform: uppercase;
        position: relative;
      }
    }
  }
}
              
            
!

JS

              
                const {
  Fragment,
  useCallback,
  useEffect,
  useLayoutEffect,
  useRef,
  useState,
} = React;

// returns a static function that will always call the latest callback
const useDynamicCallback = value => {
  const ref = useRef(value);
  useEffect(() => {
    ref.current = value;
  });
  return useCallback(() => ref.current(), []);
}

const useScrollSpy = handleScroll => {
  // static callback means we don't have to sub/unsub on each render
  const onScroll = useDynamicCallback(handleScroll);
  
  useLayoutEffect(() => {
    // Create scroll listener and call it once to initialize
    document.addEventListener('scroll', onScroll);
    onScroll();

    // Clean up scroll listener on unmount
    return () => document.removeEventListener('scroll', onScroll);
  }, []);
};

const Page = ({title, subtitle, background}) => {
  const style = { backgroundImage: `url("${background}")` };
  const bgStyle = { ...style, left: 0, right: 0 };
  
  const bgRef = useRef();
  const centerRef = useRef();
  const pageRef = useRef();
  const staticRef = useRef();
  
  // useScrollSpy to update on scroll
  useScrollSpy(() => {
    const {scrollTop} = document.scrollingElement;
    const offset = scrollTop - pageRef.current.offsetTop;
    staticRef.current.style.clipPath = `inset(${-offset}px 0 0)`;
    
    const {offsetTop, offsetHeight} = centerRef.current;
    const pageHeight = pageRef.current.offsetHeight;
    bgRef.current.style.top     = `-${offsetTop}px`;
    bgRef.current.style.bottom  = `${offsetTop + offsetHeight - pageHeight}px`;
  });
  
  return (
    <div className="page" style={style} ref={pageRef}>
      <div className="static" ref={staticRef}>
        <div className="centered" ref={centerRef}>
          <div className='bg' style={bgStyle} ref={bgRef} />
          <h1>{title}</h1>
          <h2>{subtitle}</h2>
        </div>
      </div>
    </div>
  )
}

const App = () => (
  <Fragment>
    <Page title="This is the first page" subtitle="Of this fancy scroll thing"
      background="http://www.hdwallpaperspulse.com/wp-content/uploads/2017/03/28/awesome-railway-road-image.jpg" />
    <Page title="This is the second page" subtitle="Of this nifty scroll thingie"
      background="http://sfwallpaper.com/images/background-images-hd-18.jpg" />
    <Page title="This is the third page" subtitle="Of this dope ass scroll shit"
      background="http://sfwallpaper.com/images/cool-background-picture-20.jpg" />
  </Fragment>
);

ReactDOM.render(<App />, document.getElementById('root'));
              
            
!
999px

Console