ImageCompare
Added in RC.11.1
Included in Mavis 0.1.0-rc.11.1 for Vue + Vite, Nuxt and NativeScript iOS/Android. Keep core and renderers on the same version.
<MImageCompare
v-model="position"
:before="original"
:after="edited"
label="Photo comparison"
beforeLabel="Original"
afterLabel="Edited"
/>| Prop | Type | Contract |
|---|---|---|
before / after | string | Required image sources. |
label / beforeLabel / afterLabel | string | Required comparison name; default side labels Before / After. |
modelValue / step | number | 50 / 1, clamped to 0–100. |
aspectRatio / orientation / disabled | number / 'horizontal' or 'vertical' / boolean | 1.5 / horizontal / false. |
hint | boolean | false. Sways the divider once after both images load. |
Both images keep their full geometry: the divider reveals a clipped image instead of squeezing it. Direct dragging follows input; buttons or external model changes animate the reveal through a Jolt numeric value. The Web slider supports arrows, Shift+arrows, Home/End and PageUp/PageDown. Native provides an accessible slider in addition to the on-image handle. Cancellation restores the starting value. Use images with matching composition for before/after comparisons; different images work for comparing alternatives. Image loading/error placeholders come from MImage.
Feel
The handle lifts and stretches along the divider while you hold it, then springs back when you let go. On the Web each keyboard step nudges it toward the side it moves to, and pushing against either end gives a small bump. With hint, the divider sways once after both images have loaded, so people discover that it moves. The hint never changes modelValue, the slider value or what assistive technology reads; it stops as soon as someone drags, presses a key or disables the control, and it is skipped under reduced motion.
<script setup lang="ts">
import { computed, ref } from 'vue'
import { mountains, coast } from '../atlas/photos'
import { useCatalogLocale } from '../locale'
const props = defineProps<{ lang?: 'en' | 'pt' }>()
const { locale } = useCatalogLocale(() => props.lang)
const pt = computed(() => (props.lang ?? locale.value) === 'pt')
const t = (en: string, br: string) => (pt.value ? br : en)
const amount = ref(50)
const vertical = ref(false)
</script>
<template>
<MColumn gap="lg">
<MColumn gap="xs"
><MText text="FIND YOUR ELSEWHERE" variant="overline" tone="primary" /><MText
:text="t('Two ways to get away.', 'Dois caminhos para sair da rotina.')"
variant="title" /><MText
:text="
t(
'A mountain morning or a day by the coast?',
'Uma manhã na montanha ou um dia à beira-mar?',
)
"
tone="muted"
/></MColumn>
<MImageCompare
v-model="amount"
:before="mountains"
:after="coast"
:label="t('Choose your landscape', 'Escolha sua paisagem')"
:beforeLabel="t('Mountains', 'Montanhas')"
:afterLabel="t('Coast', 'Litoral')"
:orientation="vertical ? 'vertical' : 'horizontal'"
hint
/>
<MRow gap="sm" wrap
><MButton
:text="t('More mountains', 'Mais montanhas')"
variant="secondary"
@click="amount = 85" /><MButton
:text="t('More coast', 'Mais litoral')"
variant="secondary"
@click="amount = 15" /><MButton
:text="t('Change direction', 'Mudar direção')"
variant="ghost"
@click="vertical = !vertical"
/></MRow>
<MText id="compare-value" :text="String(amount)" variant="caption" tone="muted" />
</MColumn>
</template>Desktop
On the Mac and on Windows the divider moves with a drag, the arrow keys, Page Up, Page Down, Home and End, and Escape puts back a drag in progress. On Windows the first picture is cut with a scroll viewer, so its corners are not rounded where the cut runs through it. See Desktop components.