How curtains.js works: HTML elements to WebGL planes
mastercurtains.js is a vanilla WebGL library that converts HTML elements (containing images or videos) into 3D WebGL textured planes.
Key Workflow:
- Define Layout in CSS: You define the size and position of your planes using standard CSS. This allows for responsive WebGL elements that follow your web page layout.
- Create a Canvas Container: A
Curtainsinstance appends a canvas to a specified container to manage the WebGL context, resize events, and the animation loop. - Bind Planes to Elements: You create
Planeobjects by binding them to specific HTML elements. These elements act as the source for the textures used in the WebGL planes. - Animate via Shaders: Once bound, you can pass uniforms (like
time) to vertex and fragment shaders to create complex 3D interactions and animations.
import {Curtains, Plane} from 'curtainsjs';
const curtains = new Curtains({
container: "canvas"
});
const plane = new Plane(curtains, document.querySelector("#plane"));