Compare
Side-by-side comparison slider component.
View SourceUsage
css
@import "winduum/src/components/compare/index.css" layer(components);
Variants
Installation
Follow instructions for individual framework usage below
Examples
Default
html
<div class="c-compare rounded size-fit accent-light">
<input type="range" step="0.1" aria-hidden="true" data-action="compareInput">
<div class="ui-btn circle" aria-hidden="true">
<svg class="size-6" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none">
<path class="-translate-x-1.5 scale-75 origin-center" stroke-linecap="round" stroke-linejoin="round" d="M15.75 19.5 8.25 12l7.5-7.5" />
<path class="translate-x-1.5 scale-75 origin-center" stroke-linecap="round" stroke-linejoin="round" d="m8.25 4.5 7.5 7.5-7.5 7.5" />
</svg>
</div>
<div class="ui-image">
<img src="https://via.placeholder.com/896x504/333/" alt="Image 1" loading="lazy" width="896" height="504">
<img src="https://via.placeholder.com/896x504/888" alt="Image 2" loading="lazy" width="896" height="504">
</div>
</div>
liquid
<script type="module">
import { setPosition, setKeyboardStep, setMouseStep } from 'winduum/src/components/compare/index.js'
document.querySelectorAll('[data-action="compareInput"]').forEach(compareInput => {
compareInput.addEventListener('input', setPosition)
compareInput.addEventListener('keydown', setKeyboardStep)
compareInput.addEventListener('mousedown', setMouseStep)
})
</script>
Text
html
<div class="c-compare rounded w-fit accent-dark">
<input type="range" step="0.1" aria-hidden="true" data-action="compareInput">
<div class="ui-btn circle" aria-hidden="true">
<svg class="size-6" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none">
<path class="-translate-x-1.5 scale-75 origin-center" stroke-linecap="round" stroke-linejoin="round" d="M15.75 19.5 8.25 12l7.5-7.5" />
<path class="translate-x-1.5 scale-75 origin-center" stroke-linecap="round" stroke-linejoin="round" d="m8.25 4.5 7.5 7.5-7.5 7.5" />
</svg>
</div>
<div class="ui-image">
<div class="bg-primary text-light text-9xl font-black grid place-content-center p-6">PRIMARY</div>
<div class="bg-main text-body text-9xl font-black grid place-content-center p-6">PRIMARY</div>
</div>
</div>
liquid
<script type="module">
import { setPosition, setKeyboardStep, setMouseStep } from 'winduum/src/components/compare/index.js'
document.querySelectorAll('[data-action="compareInput"]').forEach(compareInput => {
compareInput.addEventListener('input', setPosition)
compareInput.addEventListener('keydown', setKeyboardStep)
compareInput.addEventListener('mousedown', setMouseStep)
})
</script>
Javascript API
setPosition
- Type:
(Event<HTMLInputElement>, options: PositionOptions) => void
- Kind:
sync
PositionOptions
selector
- Type:
string
- Default:
.c-compare
positionProperty
- Type:
string
- Default:
--c-compare-position
setKeyboardStep
- Type:
(KeyboardEvent<HTMLInputElement>, step: number) => void
- Kind:
sync
setMouseStep
- Type:
(MouseEvent<HTMLInputElement>, step: number) => void
- Kind:
sync