Compare

A before and after view split by a draggable divider.

Installation

Import the class, and @use the entry point in your global styles: without it the component renders unstyled.

import { Component } from '@angular/core';
import { WrCompare } from 'ngwr/compare';

@Component({ imports: [WrCompare] })
export class MyComponent {}

Image compare

Mark the layers wrCompareBefore and wrCompareAfter; drag the divider or use the arrow keys (Shift moves 10 points).

<wr-compare [(position)]="pos">
  <img wrCompareBefore src="before.jpg" alt="" />
  <img wrCompareAfter src="after.jpg" alt="" />
</wr-compare>
Before
After

Vertical split

orientation="vertical" splits top from bottom.

<wr-compare orientation="vertical">
  <img wrCompareBefore src="before.jpg" alt="" />
  <img wrCompareAfter src="after.jpg" alt="" />
</wr-compare>
Before
After

Arbitrary content

Any content works; without an image to size it, set a height on <wr-compare>.

<wr-compare style="height: 12rem">
  <div wrCompareBefore>…before content…</div>
  <div wrCompareAfter>…after content…</div>
</wr-compare>
Before
After

API

NameDescriptionTypeDefault
positionDivider position as a percentage (0–100). Two-way bindable.number50
ariaLabelAccessible name of the divider. Falls back to compare.label.string | nullnull
orientationDivider direction: - 'horizontal' — divider line is vertical, drags left/right. - 'vertical' — divider line is horizontal, drags up/down.'horizontal' | 'vertical''horizontal'
showHandleShow the round drag handle on the divider.booleantrue
disabledDisable interaction (divider stays put).booleanfalse
minPositionLowest position the divider may reach, in percent.number0
maxPositionHighest position the divider may reach, in percent.number100

Content slots

NameDescriptionTypeDefault
[wrCompareBefore] / [wrCompareAfter]Attributes marking the two pieces of projected content.attr—

See also