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>Scroll</h1>
<div class="book">
  <div class="book__spine"></div>
  <div class="page book__page book__cover book__cover--front" style="--page-index: 1;">
    <div class="page__half page__half--front">
      <svg class="sticker" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 316 306">
        <path d="M155 0c-37 0-63 8-85 30-6-6-21-7-29-7C22 23 6 38 6 56c1 24 9 34 24 40l-9 2-21 4 3 22c3 0 8 1 9 4 6 7 2 14 3 26 2 21 7 33 14 40 14 67 62 112 127 112 70 0 118-45 132-112 6-7 11-20 13-40 1-12-3-19 3-26 2-3 6-4 9-4l3-22-21-4-10-2c17-7 24-26 24-40 0-18-15-33-34-33-9 0-23 1-30 7-23-22-51-30-90-30z" fill="hsl(0, 0%, 96%)"></path>
        <g transform="matrix(1.34105 0 0 1.34105 -43 -1047)">
          <path d="M243 894c0 61-36 106-94 106-55 0-92-45-92-106s38-86 91-86 95 25 95 86z" fill="#803300"></path>
          <path d="M212 958c0 20-29 39-63 39-35 0-61-19-61-39s26-33 61-33 63 13 63 33z" fill="#e9c6af"></path>
          <path d="M181 932c0 7-19 24-30 24s-32-17-32-24c0-8 20-13 31-13 12 0 31 5 31 13z"></path>
          <ellipse cx="68.3" cy="827.7" rx="23.8" ry="23.1" fill="#803300"></ellipse>
          <path d="M85 826a17 16 0 00-17-14 17 16 0 00-16 16 17 16 0 0016 16 17 16 0 001 0l3-4a66 66 0 0111-12l2-2z" fill="#e9c6af"></path>
          <ellipse ry="23.1" rx="23.8" cy="827.7" cx="-231.2" transform="scale(-1 1)" fill="#803300"></ellipse>
          <path d="M215 826a17 16 0 0116-14 17 16 0 0117 16 17 16 0 01-17 16 17 16 0 01-1 0l-2-4a66 66 0 00-11-12l-2-2z" fill="#e9c6af"></path>
          <path d="M148 815c-14 0-26 1-38 4v11a199 199 0 0180 1v-11c-13-3-27-5-42-5z" fill="red"></path>
          <path d="M165 816a16 8 0 015 5 16 8 0 01-6 6l26 4v-11l-25-4z" fill="#e50000"></path>
          <path d="M148 789c-43 0-76 20-83 64 12-11 28-19 45-23 0 0-2-12 10-16 15-4 19-4 28-4 10 0 15 0 30 4s12 17 12 17c18 5 32 11 45 22-8-46-43-64-87-64z" fill="#1a1a1a"></path>
          <circle cx="97.2" cy="894.1" r="11.2" fill="#faa" fill-opacity=".6"></circle>
          <circle cy="894.1" cx="201.9" r="11.2" fill="#faa" fill-opacity=".6"></circle>
          <path d="M97 864a21 21 0 01-7 16 21 21 0 01-16 5M204 864a21 21 0 006 16 21 21 0 0016 5" fill="none" stroke="#e9afaf" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"></path>
          <g>
            <path d="M77 855c-6 0-13 0-23 2l-14 3 2 15 7 2c3 5 1 10 2 18 3 28 12 34 26 35 8 1 23 3 33-1s19-10 25-18c6-9 6-18 10-26 3-5 8-4 10 0 3 8 4 17 10 26 6 8 15 14 24 18 11 4 26 2 34 1 14-1 23-7 26-35 1-8-2-13 2-18l7-2 2-15-15-3c-15-3-23-2-34-2h-13l-25 4c-8 2-15 7-23 6-8 0-15-5-23-6l-25-4H77z"></path>
            <path d="M85 860c-10 1-25 1-28 13-3 15-3 32 6 45 7 11 23 9 35 9 19-1 35-16 40-34 2-8 4-14 1-19-6-10-20-12-31-13l-23-1z" fill="#333"></path>
            <path d="M56 864a4 2 0 01-4 2 4 2 0 01-4-2 4 2 0 014-1 4 2 0 014 1" fill="#b3b3b3"></path>
            <path d="M215 860c10 1 24 1 28 13 3 15 3 32-6 45-7 11-23 9-35 9-19-1-35-16-40-34-2-8-4-14-1-19 6-10 20-12 31-13l23-1z" fill="#333"></path>
            <path d="M244 864a4 2 0 004 2 4 2 0 004-2 4 2 0 00-4-1 4 2 0 00-4 1" fill="#b3b3b3"></path>
            <path d="M101 861l-19 66h17l18-65-16-1zM89 860h-4l-3 1-18 59 6 5z" fill="#fff"></path>
          </g>
        </g>
      </svg>
    </div>
    <div class="page__half page__half--back">
      <div class="book__insert"></div>
    </div>
  </div>
  <div class="page book__page" style="--page-index: 2;">
    <div class="page__half page__half--front"><a href="https://codepen.io/jh3y/full/jJVpWZ" target="_blank" rel="noreferrer noopener"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/605876/Pancake-sketch.svg" /></a>
      <div class="page__number">1</div>
    </div>
    <div class="page__half page__half--back"><a href="https://codepen.io/jh3y/full/eYpmBxQ" target="_blank" rel="noreferrer noopener"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/605876/Tcannon-sketch.svg" /></a>
      <div class="page__number">2</div>
    </div>
  </div>
  <div class="page book__page" style="--page-index: 3;">
    <div class="page__half page__half--front"><a href="https://codepen.io/jh3y/full/RwWMwvY" target="_blank" rel="noreferrer noopener"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/605876/Elon-sketch.svg" /></a>
      <div class="page__number">3</div>
    </div>
    <div class="page__half page__half--back"><a href="https://codepen.io/jh3y/full/RwraKYZ" target="_blank" rel="noreferrer noopener"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/605876/Record-sketch.svg" /></a>
      <div class="page__number">4</div>
    </div>
  </div>
  <div class="page book__page" style="--page-index: 4;">
    <div class="page__half page__half--front"><a href="https://codepen.io/jh3y/full/QWbRxXb" target="_blank" rel="noreferrer noopener"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/605876/Cubes-sketch.svg" /></a>
      <div class="page__number">5</div>
    </div>
    <div class="page__half page__half--back"><a href="https://codepen.io/jh3y/full/eYpGQxr" target="_blank" rel="noreferrer noopener"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/605876/Pokedex-sketch.svg" /></a>
      <div class="page__number">6</div>
    </div>
  </div>
  <div class="page book__page" style="--page-index: 5;">
    <div class="page__half page__half--front"><a href="https://codepen.io/jh3y/full/MWWowEb" target="_blank" rel="noreferrer noopener"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/605876/Truck-sketch.svg" /></a>
      <div class="page__number">7</div>
    </div>
    <div class="page__half page__half--back"><a href="https://codepen.io/jh3y/full/RwPrOoz" target="_blank" rel="noreferrer noopener"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/605876/Care-sketch.svg" /></a>
      <div class="page__number">8</div>
    </div>
  </div>
  <div class="page book__page" style="--page-index: 6;">
    <div class="page__half page__half--front"><a href="https://codepen.io/jh3y/full/NWqemYK" target="_blank" rel="noreferrer noopener"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/605876/Moon-sketch.svg" /></a>
      <div class="page__number">9</div>
    </div>
    <div class="page__half page__half--back"><a href="https://codepen.io/jh3y/full/abzeaWJ" target="_blank" rel="noreferrer noopener"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/605876/Newton-sketch.svg" /></a>
      <div class="page__number">10</div>
    </div>
  </div>
  <div class="page book__page" style="--page-index: 7;">
    <div class="page__half page__half--front"><a href="https://codepen.io/jh3y/full/rNOqzbN" target="_blank" rel="noreferrer noopener"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/605876/Launch-sketch.svg" /></a>
      <div class="page__number">11</div>
    </div>
    <div class="page__half page__half--back"><a href="https://codepen.io/jh3y/full/GRoKOyg" target="_blank" rel="noreferrer noopener"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/605876/Gun-sketch.svg" /></a>
      <div class="page__number">12</div>
    </div>
  </div>
  <div class="page book__page" style="--page-index: 8;">
    <div class="page__half page__half--front"><a href="https://codepen.io/jh3y/full/LYpNyvm" target="_blank" rel="noreferrer noopener"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/605876/Kitkat-sketch.svg" /></a>
      <div class="page__number">13</div>
    </div>
    <div class="page__half page__half--back"><a href="https://codepen.io/jh3y/full/zYGQYWJ" target="_blank" rel="noreferrer noopener"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/605876/Fireflies-sketch.svg" /></a>
      <div class="page__number">14</div>
    </div>
  </div>
  <div class="page book__page" style="--page-index: 9;">
    <div class="page__half page__half--front"><a href="https://codepen.io/jh3y/full/jOOYMLm" target="_blank" rel="noreferrer noopener"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/605876/Matryoshka-sketch.svg" /></a>
      <div class="page__number">15</div>
    </div>
    <div class="page__half page__half--back"><a href="https://codepen.io/jh3y/full/BaobKOJ" target="_blank" rel="noreferrer noopener"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/605876/Birthday-sketch.svg" /></a>
      <div class="page__number">16</div>
    </div>
  </div>
  <div class="page book__page" style="--page-index: 10;">
    <div class="page__half page__half--front"><a href="https://codepen.io/jh3y/full/eYpdPWa" target="_blank" rel="noreferrer noopener"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/605876/Train-sketch.svg" /></a>
      <div class="page__number">17</div>
    </div>
    <div class="page__half page__half--back"><a href="https://codepen.io/jh3y/full/aPzVme" target="_blank" rel="noreferrer noopener"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/605876/Earth-sketch.svg" /></a>
      <div class="page__number">18</div>
    </div>
  </div>
  <div class="page book__page" style="--page-index: 11;">
    <div class="page__half page__half--front"><a href="https://codepen.io/jh3y/full/MWwRKvd" target="_blank" rel="noreferrer noopener"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/605876/Cloud-sketch.svg" /></a>
      <div class="page__number">19</div>
    </div>
    <div class="page__half page__half--back"><a href="https://codepen.io/jh3y/full/ZjLKGY" target="_blank" rel="noreferrer noopener"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/605876/Impossible-sketch.svg" /></a>
      <div class="page__number">20</div>
    </div>
  </div>
  <div class="page book__page book__cover book__cover--back" style="--page-index: 12;">
    <div class="page__half page__half--front"></div>
    <div class="page__half page__half--back"></div>
    <div class="book__insert"><a href="https://jhey.dev" target="_blank" rel="noopener noreferrer"><img class="logo" src="https://assets.codepen.io/605876/bear-with-cap.svg" /></a></div>
  </div>
</div>
              
            
!

CSS

              
                @import "https://unpkg.com/normalize.css";

* {
  box-sizing: border-box;
}
:root {
  --page-count: 20;
  --page-scroll: 25;
  --underline: rgba(64, 64, 64, 0.4);
  --spine: #000;
  --cover: #1a1a1a;
  --bg: #4d4d4d;
  --insert: #d9d9d9;
  --page: #e6e6e6;
}
h1 {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  margin: 0;
  font-size: 2rem;
  color: #808080;
  font-family: "Google sans", sans-serif;
}
body {
  width: 100vw;
  height: calc(((var(--page-count) + 2) * var(--page-scroll)) * 1vh);
  background: var(--bg);
  overflow-x: hidden;
}
.page {
  height: 100%;
  width: 100%;
  position: relative;
  transform-style: preserve-3d;
}
.page .page__number {
  position: absolute;
  color: #808080;
  bottom: 1rem;
  font-size: 1vmin;
}
.page__half--front .page__number {
  right: 1rem;
}
.page__half--back .page__number {
  left: 1rem;
}
.page__half {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  transform: rotateY(calc(var(--rotation) * 1deg))
    translate3d(0, 0, calc((0.5 * var(--coefficient)) * 1px));
  -webkit-clip-path: inset(0 0.5% 0 0.5%);
  clip-path: inset(0 0.5% 0 0.5%);
}
.page__half--front {
  --rotation: 0;
  --coefficient: 0;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  border-radius: 0 5% 5% 0;
}
.page__half--back {
  --rotation: 180;
  --coefficient: 2;
  border-radius: 5% 0 0 5%;
}
.book {
  height: 40vmin;
  position: fixed;
  width: 30vmin;
  min-width: 150px;
  min-height: 200px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.5);
  transform-style: preserve-3d;
  perspective: 1200px;
}
.book__insert {
  content: "";
  position: absolute;
  height: 94%;
  width: 94%;
  background: var(--insert);
  top: 50%;
  right: -1rem;
  transform: translate(0, -50%);
  border-radius: 5% 0 0 5%;
}
.book__spine {
  height: 100%;
  left: 0;
  top: 0;
  position: absolute;
  background: var(--spine);
  transform-origin: 0 50%;
  width: 12px;
  transform: translate3d(0, 0, -13px) scaleX(1) rotateY(0deg);
}
.book__page {
  position: absolute;
  left: 2%;
  top: 50%;
  border-radius: 0 5% 5% 0;
  transform: translate(0, -50%);
  height: 94%;
  width: 94%;
  z-index: calc(((var(--page-count) + 2) - var(--page-index)) * 2);
  transform-origin: 0% 50%;
}
.book__cover {
  border-radius: 0 5% 5% 0;
  height: 100%;
  width: 100%;
  position: absolute;
  top: 50%;
  left: 0;
  background: var(--cover);
}
.book__cover--front {
  transform-origin: 0 50%;
}
.book__cover--front .page__half--back {
  border-right: 1rem solid var(--spine);
}
.book__cover--back {
  transform-origin: 0% 50%;
}
.book__cover--back .page__half--front {
  border-left: 1rem solid var(--spine);
}
.book__cover--back .book__insert {
  left: 0;
  border-radius: 0 5% 5% 0;
}
.book__page:not(.book__cover) .page__half {
  background: repeating-linear-gradient(
        0deg,
        transparent 0 1rem,
        var(--underline) 1rem calc(1rem + 1px),
        transparent calc(1rem + 1px)
      )
      0 1rem/100% 100% no-repeat,
    var(--page);
}
.sticker {
  height: 15%;
  position: absolute;
  bottom: 5%;
  right: 5%;
  transform: rotate(-25deg);
}
.code {
  line-height: 1.2;
  font-family: monospace;
  white-space: pre-line;
  max-width: 100%;
  max-height: 100%;
  font-weight: bold;
  color: #0f0f0f;
  text-shadow: 2px 2px 0 #1c1c1c;
  border-radius: 5%;
  display: block;
  overflow: hidden;
}
.logo {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  opacity: 0;
  height: 25%;
}
img {
  width: 90%;
  height: 90%;
  -o-object-fit: center;
  object-fit: center;
  z-index: 2;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
a {
  height: 100%;
  width: 100%;
  position: relative;
  display: block;
}

              
            
!

JS

              
                import { gsap } from "https://cdn.skypack.dev/gsap@3.11.0";
import { ScrollTrigger } from "https://cdn.skypack.dev/gsap@3.11.0/ScrollTrigger";

const { to, set } = gsap;

gsap.registerPlugin(ScrollTrigger);

to(".book", {
  scrollTrigger: {
    scrub: 1,
    start: () => 0,
    end: () => window.innerHeight * 0.25
  },
  scale: 1
});

to(".logo", {
  scrollTrigger: {
    scrub: true,
    start: () => 13.5 * (window.innerHeight * 0.25),
    end: () => 14 * (window.innerHeight * 0.25)
  },
  opacity: 1
});

const PAGES = [...document.querySelectorAll(".book__page")];
PAGES.forEach((page, index) => {
  set(page, { z: index === 0 ? 13 : -index * 1 });
  if (index === 11) return false;
  to(page, {
    rotateY: `-=${180 - index / 2}`,
    scrollTrigger: {
      scrub: 1,
      start: () => (index + 1) * (window.innerHeight * 0.25),
      end: () => (index + 2) * (window.innerHeight * 0.25)
    }
  });
  to(page, {
    z: index === 0 ? -13 : index,
    scrollTrigger: {
      scrub: 1,
      start: () => (index + 1) * (window.innerHeight * 0.25),
      end: () => (index + 1.5) * (window.innerHeight * 0.25)
    }
  });
});

              
            
!
999px

Console