Diff component shows a side-by-side or before/after comparison. Perfect for image comparisons and visual changes.
Basic Example
Image comparison with drag resizer
const { default: Diff } = await import('/components/data-display/diff.js');
const { tags, $ } = Lightview;
const diff = Diff({ style: 'max-width: 500px; min-height: 300px;' },
Diff.Item1({ src: 'https://picsum.photos/600/400?grayscale', alt: 'Before (Grayscale)' }),
Diff.Item2({ src: 'https://picsum.photos/600/400', alt: 'After (Color)' }),
Diff.Resizer({})
);
$('#example').content(diff);
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| aspectRatio | string | 'aspect-video' | Aspect ratio class (aspect-video, aspect-square, etc.) |
Sub-components
| Component | Props | Description |
|---|---|---|
Diff.Item1 |
src, alt | Top comparison item (The "Before" overlay) |
Diff.Item2 |
src, alt | Bottom comparison item (The "After" background) |
Diff.Resizer |
- | Drag handle for resizing |