HSL Color Cycling

Loop-based event handling with dynamic color generation
This example demonstrates a sophisticated pattern: using an event-driven loop to continuously animate colors while the pointer is held down. Zero JavaScript required!
repeat until pointerdown/pointerup transition Math.random() template strings
Instructions: Press and hold on the box below. Watch the colors cycle while you hold! Release to stop.
Press & Hold Me!

The Code

<div id="color-box" _="on pointerdown set originalColor to my *background-color repeat until event pointerup from the document set rand to Math.random() * 360 transition *background-color to `hsl(${rand} 100% 90%)` over 250ms end transition *background-color to originalColor end"> Press & Hold Me! </div>

How it works:

  1. Save original color: set originalColor to my *background-color
  2. Start event loop: repeat until event pointerup from the document
  3. Generate random hue: set rand to Math.random() * 360
  4. Animate color: transition *background-color to `hsl(${rand} 100% 90%)` over 250ms
  5. Loop continues until pointer is released
  6. Restore original: transition *background-color to originalColor

Advanced Concepts:

Why this pattern is powerful:

Try it yourself: