Portfolio
  • 01Home
  • 02Projects
  • 03About
  • 04Skills
  • 05Lab
  • 06Writing
  • 07Contact

© 2026 Hamza Syrage

LabView all
Arrow FieldCursorCursor SpotlightCursorGooey CursorCursorImage CompareMediaInteractive ChartDataMagnetic ButtonInteractionMarquee RevealTypographyMorphing ShapeAnimationsNested ViewsOverlaysOdometer CounterDataParticle ConstellationCanvasRipple ClickButtonsScroll RevealScrollShuffle GridLayoutStep WizardNavigationTabsNavigationTilt CardCards

UI Experiments

All Lab Entries
Media

Image Compare

A draggable before/after slider that reveals two images with a clip-path mask.

A before/after image slider that works entirely with CSS clip-path and pointer tracking. No canvas, no WebGL, just clipping.

#Step 1 - Clip-path basics

The "after" image sits on top of the "before" image and is clipped with inset(0 0 0 50%). The four values are top, right, bottom, left. Changing the left value reveals more or less of the top image.

Static split at 50%

Before
After
tsx
Loading...

#Step 2 - Pointer tracking

Track the cursor's X position relative to the container and map it to a percentage. The clip-path updates on every mouse move, creating the drag-to-reveal effect.

Click and drag to compare

Before
After
tsx
Loading...

#Step 3 - Drag handle

Add a vertical line and grabber at the split point so users know where to grab. The hit area is 40px wide, with the visible line centered inside. Moving onMouseMove to the window prevents losing the drag when the cursor leaves the container.

Vertical handle with cursor hint

Before
After
↔
tsx
Loading...

#Step 4 - Touch support

Add onTouchMove alongside onMouseMove using useRef for the dragging state. This avoids an unnecessary re-render on every pointerdown, and handles both mouse and touch input.

Works on touch and mouse

Before
After
↔
tsx
Loading...

#Step 5 - Configuration

Adjust the starting position to control which image is revealed by default. The CSS custom property --position drives both the clip-path and the handle position.

Adjust the slider to set starting position

Starting position50%
Before
After
↔
tsx
Loading...

#Configuration

Tweak the starting position and handle style. The code updates in real-time.

Before
After
All parameters
Start position50%
Handle style
tsx
Loading...