Page Curl shader preview: The page peels back from a corner, following the pointer.
ittybitty

Page Curl

The page peels back from a corner, following the pointer.

Code

The usage always matches the preview, layers and performance settings included. No build step or package.

Use as
Code view

Copy embed gives one block to paste into any page or site builder, no setup. For your own code: add page-curl.js, ittybitty-shader.js, runtime.js, pointer.js, texture.js next to this page. Highlighted values follow the controls.

<!-- Quickest: one element. Size it with CSS; it fills its box. -->
<script type="module" src="./ittybitty-shader.js"></script>
<ittybitty-shader effect="page-curl" style="width: 100%; aspect-ratio: 16 / 10;"></ittybitty-shader>

<!-- Or with JavaScript, for full control: -->
<canvas id="page-curl" aria-hidden="true" style="width: 100%; aspect-ratio: 16 / 10; display: block"></canvas>

<script type="module">
  import { pageCurl } from './page-curl.js';

  const canvas = document.getElementById('page-curl');
  const effect = pageCurl(canvas, {
    showUnder: true,
    showShadow: true,
    showThrough: true,
    image: '',
    corner: 'bottom-right',
    curl: 0.22,
    radius: 0.5,
    speed: 0.5,
    interactive: true,
    responsiveness: 0.5,
    back: '#f3efe7',
    under: '#2a2622',
    // Performance
    dpr: 2,
    adaptive: true,
  });

  // Later: effect.set(…), effect.pause(), effect.resume(), effect.destroy()
</script>

Details

The sheet wraps around a cylinder along a fold line: the part past it rolls over and comes back flipped, showing the reverse of the paper with the print faintly through it, and casts a soft shadow on what it reveals, your page or a colour. The corner follows the pointer, peeling further the further it is drawn, and breathes gently at rest.

Payload
6.9 KB brotli for page-curl.js and ittybitty-shader.js and runtime.js and pointer.js and texture.js, measured at build time. See the method.
Resolution
Device pixel ratio capped at 2.
Frame rate
Display rate while breathing or following the pointer.
When unseen
Stops rendering when the canvas leaves the viewport or the tab is hidden, and resumes where it left off.
Reduced motion
Holds still at rest; the pointer still peels it.
Layers
Up to five effects fuse into one shader and one draw call. Filters such as dithering and halftone process the layers beneath them.
Browsers
Any browser with WebGL2: Chrome and Edge 56+, Firefox 51+, Safari 15+.
Licence
MIT. Copy it, change it, ship it.