惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 三生石上(FineUI控件)
Martin Fowler
Martin Fowler
月光博客
月光博客
AI
AI
B
Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
C
CXSECURITY Database RSS Feed - CXSecurity.com
WordPress大学
WordPress大学
GbyAI
GbyAI
L
Lohrmann on Cybersecurity
O
OpenAI News
Schneier on Security
Schneier on Security
P
Palo Alto Networks Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Troy Hunt's Blog
V2EX - 技术
V2EX - 技术
W
WeLiveSecurity
L
LINUX DO - 最新话题
人人都是产品经理
人人都是产品经理
S
Security Affairs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
A
Arctic Wolf
Recorded Future
Recorded Future
Microsoft Security Blog
Microsoft Security Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
G
GRAHAM CLULEY
N
Netflix TechBlog - Medium
TaoSecurity Blog
TaoSecurity Blog
C
Check Point Blog
Scott Helme
Scott Helme
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Apple Machine Learning Research
Apple Machine Learning Research
PCI Perspectives
PCI Perspectives
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Vercel News
Vercel News
The Hacker News
The Hacker News
Y
Y Combinator Blog
Latest news
Latest news
SecWiki News
SecWiki News
Hugging Face - Blog
Hugging Face - Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Google Online Security Blog
Google Online Security Blog
Webroot Blog
Webroot Blog
Google DeepMind News
Google DeepMind News
Recent Commits to openclaw:main
Recent Commits to openclaw:main
C
Cisco Blogs
博客园_首页
H
Hackread – Cybersecurity News, Data Breaches, AI and More
宝玉的分享
宝玉的分享
L
LINUX DO - 热门话题

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
Build a scroll-driven WebGL hero in 30 lines
TommyDee · 2026-05-23 · via DEV Community

Hero sections that respond to scroll are one of those features that look complicated and actually aren't, once you have the right pieces. Two images, a shader that morphs between them, scroll position drives the morph. That's it. The rest is plumbing.

This tutorial builds exactly that — a scroll-driven WebGL hero — in about 30 lines of JavaScript. Plain HTML, no framework, no build step. Drop it into a CodePen or a static HTML file and it works.

What we're building

Three behaviors, tied together:

  1. As the user scrolls down into the hero section, image A morphs into image B.
  2. While the hero is centered in the viewport, the morph holds on image B.
  3. As the user scrolls down past the hero, image B morphs back to image A. That's the standard scroll-driven hero shape. Sites like Apple's product pages, Linear's marketing, and Vercel's case studies all use this pattern. The trick is the holding part — without it, the transition feels like it ends too fast and the user never sees the destination.

The dependencies

Two npm packages, both MIT, both tiny.

pnpm add @vysmo/scroll @vysmo/transitions

Enter fullscreen mode Exit fullscreen mode

Combined, that's about 6 KB gzipped. Less than a logo SVG.

The HTML

A section, a canvas, two <img> elements that we'll use as transition sources, plus some content above and below to give the page something to scroll through:

<section style="height: 200vh; padding-top: 50vh;">
  <h2>Above the hero</h2>
  <p>Scroll down to see the effect.</p>
</section>

<section id="hero" style="height: 100vh; position: relative;">
  <canvas id="hero-canvas" style="width: 100%; height: 100%;"></canvas>
  <img id="img-a" src="/from.jpg" style="display: none;" />
  <img id="img-b" src="/to.jpg" style="display: none;" />
</section>

<section style="height: 200vh;">
  <h2>Below the hero</h2>
  <p>Keep scrolling.</p>
</section>

Enter fullscreen mode Exit fullscreen mode

The two <img> elements are display: none because we're not rendering them as DOM — we're passing them to WebGL as texture sources. The browser still decodes them, which is what we need.

The JavaScript — 30 lines

import { Runner, crossZoom } from "@vysmo/transitions";
import { createScrollTransition, scrollPlateau } from "@vysmo/scroll";

const section = document.querySelector<HTMLElement>("#hero")!;
const canvas = document.querySelector<HTMLCanvasElement>("#hero-canvas")!;
const from = document.querySelector<HTMLImageElement>("#img-a")!;
const to = document.querySelector<HTMLImageElement>("#img-b")!;

// Wait for both images to decode before we use them as textures.
await Promise.all([from.decode(), to.decode()]);

// Match the canvas backing store to its CSS size so the shader renders sharp.
const dpr = Math.min(window.devicePixelRatio, 2);
canvas.width = canvas.clientWidth * dpr;
canvas.height = canvas.clientHeight * dpr;

// One WebGL2 runner per canvas. It owns the compiled programs and FBOs.
const runner = new Runner({ canvas });

// Bind scroll progress to the transition.
createScrollTransition({
  section,
  runner,
  transition: crossZoom,
  from,
  to,
  // Hold the "to" image while the section is 30%–70% through the viewport.
  ease: scrollPlateau(0.3, 0.7),
});

Enter fullscreen mode Exit fullscreen mode

That's the whole thing. Let me walk through the parts that aren't obvious.

What scrollPlateau does

This is the part of the API I'd most like to spend a paragraph on, because it's the small idea that makes the whole pattern work.

Raw scroll progress is a 0 → 1 line as the section moves through the viewport. If you feed that directly into a transition, you get a morph that starts the moment the section enters and ends the moment it exits — which means the user only briefly sees the destination image as it flies past. Unsatisfying.

scrollPlateau(0.3, 0.7) reshapes that linear progress into a bathtub curve:

  • 0.0 → 0.3 of scroll progress: transition plays 0 → 1
  • 0.3 → 0.7 of scroll progress: transition stays at 1 (the "hold")
  • 0.7 → 1.0 of scroll progress: transition plays 1 → 0 The result: the morph happens quickly as the section enters, the destination image gets to live on screen for the comfortable middle stretch, and the morph reverses on exit. Visually, the user feels like they "arrived" at something, instead of like something whisked past them.

You can change the plateau bounds to taste — scrollPlateau(0.1, 0.9) makes the entry and exit transitions very fast, scrollPlateau(0.4, 0.6) is slower and more deliberate.

Swap the transition for a totally different feel

The line transition: crossZoom is the one that defines the look. There are 60 built-in transitions, and switching is one identifier:

import { pageCurl } from "@vysmo/transitions";
// ...
createScrollTransition({ section, runner, transition: pageCurl, from, to, ease });

Enter fullscreen mode Exit fullscreen mode

Now image A peels back like a page turn to reveal image B as you scroll. Same 30 lines of code, completely different aesthetic.

A few transitions worth trying for a hero:

  • crossZoom — the cinematic default; image A zooms in as it fades into B
  • pageCurl — editorial, like turning a magazine page
  • paintBleed — a paint-pour reveal, looks great for product launches
  • warpZoom — a chromatic warp; perfect for tech aesthetics
  • glassShatter — image A shatters into B; high-drama, use sparingly Each is a one-line change to the import and the transition prop. The catalog has all of them with live previews.

What's happening under the hood

In case the magic feels suspicious, here's what's actually running:

  1. createScrollTransition registers your section with a shared IntersectionObserver and a single requestAnimationFrame loop (one rAF for all Vysmo scroll bindings on the page — that part matters for performance when you have multiple sections).
  2. On every animation frame where the section is intersecting the viewport, it computes a raw 0 → 1 progress value from the section's bounding-box position.
  3. It passes that value through the ease function (scrollPlateau in our case) to get a morphed progress.
  4. It calls runner.render(transition, { from, to, progress }). The runner has the compiled WebGL2 shader cached, so this is just uniform updates and a draw call — sub-millisecond on a modern phone. No internal timers, no playback state, no "play" / "pause" / "reverse" — the renderer is idempotent. You give it a progress value, it draws that frame. Scroll up and the same code path runs the transition backwards. That's why the same library works equally well for rAF-driven animations, GSAP timelines, video exports, and scroll bindings.

Common gotchas

Image must be decoded first. If you skip the await Promise.all([from.decode(), to.decode()]) line, the first render might happen with one or both textures empty, and you'll see a flash of black. Always decode before passing to the Runner.

Canvas DPR. Without the canvas.width = canvas.clientWidth * dpr lines, the canvas backing store is whatever the browser defaults to (usually 300×150 px), which makes everything look like a pixelated mess. Match the backing store to the CSS size times device pixel ratio.

Don't run on iOS Low Power Mode. WebGL2 still works there but performance is throttled — the rAF callback may only fire 30 times per second instead of 60. Your transition will look choppy. Test on a real phone, not just your laptop with throttling disabled.

When you'd want more

This 30-line version covers a single hero. As your page gets more complex — multiple scroll-driven sections, scroll-driven text reveals layered on top, scroll-driven effects (a bloom that ramps as you enter, identity in the middle, fades on exit) — the same @vysmo/scroll package has primitives for those too:

  • createScrollEffect — drives a @vysmo/effects filter through the same three-zone envelope
  • createScrollProgress — raw 0 → 1 emitter you can wire to anything (opacity, transform, your own state)
  • sharedScrollObserver — for when you're building your own scroll-driven renderer and want to plug into the same single-rAF batching But you don't need any of that today. 30 lines, two images, one transition, one envelope. That's a shippable hero.

Try it

Full example, copy-pasteable, including the HTML scaffolding:

<!doctype html>
<html>
  <head><title>Vysmo Hero Demo</title></head>
  <body style="margin:0;font-family:system-ui;">
    <section style="height:200vh;padding-top:50vh;">
      <h2 style="text-align:center;">Scroll down</h2>
    </section>

    <section id="hero" style="height:100vh;position:relative;">
      <canvas id="hero-canvas" style="width:100%;height:100%;display:block;"></canvas>
      <img id="img-a" src="/from.jpg" style="display:none;" />
      <img id="img-b" src="/to.jpg" style="display:none;" />
    </section>

    <section style="height:200vh;">
      <h2 style="text-align:center;">Keep scrolling</h2>
    </section>

    <script type="module">
      import { Runner, crossZoom } from "https://esm.sh/@vysmo/transitions";
      import { createScrollTransition, scrollPlateau } from "https://esm.sh/@vysmo/scroll";

      const section = document.querySelector("#hero");
      const canvas = document.querySelector("#hero-canvas");
      const from = document.querySelector("#img-a");
      const to = document.querySelector("#img-b");

      await Promise.all([from.decode(), to.decode()]);

      const dpr = Math.min(window.devicePixelRatio, 2);
      canvas.width = canvas.clientWidth * dpr;
      canvas.height = canvas.clientHeight * dpr;

      const runner = new Runner({ canvas });
      createScrollTransition({
        section, runner,
        transition: crossZoom,
        from, to,
        ease: scrollPlateau(0.3, 0.7),
      });
    </script>
  </body>
</html>

Enter fullscreen mode Exit fullscreen mode

Drop two images named from.jpg and to.jpg next to that file, open it in a browser, and you have a working scroll-driven WebGL hero.

The full catalog of transitions with live previews is at vysmo.com/transitions, and the scroll package docs are at vysmo.com/scroll. Source: github.com/vysmodev/vysmo. All MIT.