@nuxt/image
You may use these UI components in your own personal or commercial projects. You may not resell, redistribute, sublicense, or package them as standalone assets or template/library packs.
Full terms: End-User License Agreement
Below you can expand the main implementation file and any supporting components. Use the “Copy” button to grab a snippet straight to your clipboard.
These are the raw components that are required to run this example. Copy-paste them into your project. Most likely you will not change anything in these files, but you can if you want to. These are the components that are used in the main implementation file.
<template>
<div
ref="container"
class="relative w-[90vw] h-[90vh] overflow-hidden bg-black select-none mx-auto"
>
<!-- Image A: visible to the LEFT of the handle -->
<img
:src="imgA"
alt=""
class="absolute inset-0 w-full h-full object-cover pointer-events-none"
:style="{ clipPath: leftClip }"
draggable="false"
@dragstart.prevent
/>
<!-- Image B: visible to the RIGHT of the handle -->
<img
:src="imgB"
alt=""
class="absolute inset-0 w-full h-full object-cover pointer-events-none"
:style="{ clipPath: rightClip }"
draggable="false"
@dragstart.prevent
/>
<!-- Divider / handle -->
<div
ref="handle"
class="absolute top-0 h-full w-1 bg-white/90 shadow z-20 cursor-ew-resize"
:style="dragStyle"
role="slider"
aria-label="Comparison slider"
tabindex="0"
:aria-valuemin="0"
:aria-valuemax="Math.round(containerWidth)"
:aria-valuenow="Math.round(x)"
>
<div
class="absolute top-1/2 -translate-y-1/2 -left-2.5 w-6 h-6 rounded-full bg-white shadow border"
/>
</div>
</div>
</template>
<script setup>
import { ref, computed, watch } from 'vue'
import { useDraggable, useElementSize } from '@vueuse/core'
const props = defineProps({
imgA: {
type: String,
default:
'/images/placeholder1.jpg'
},
imgB: {
type: String,
default:
'/images/placeholder2.jpg'
}
})
const container = ref(null)
const handle = ref(null)
const { width: containerWidth } = useElementSize(container)
const { x, style: dragStyle } = useDraggable(handle, { container, axis: 'x' })
// Start centered when size known
watch(containerWidth, w => {
if (w) x.value = w / 2
})
// Complementary masks based on the handle's X
const leftClip = computed(() => {
const w = containerWidth.value || 0
const clamped = Math.max(0, Math.min(x.value, w))
// Show left side up to X: inset(top, right, bottom, left)
// Right inset hides everything to the right of the handle
const rightInset = Math.max(0, w - clamped)
return `inset(0 ${Math.round(rightInset)}px 0 0)`
})
const rightClip = computed(() => {
const w = containerWidth.value || 0
const clamped = Math.max(0, Math.min(x.value, w))
// Show right side from X onward by hiding left part
return `inset(0 0 0 ${Math.round(clamped)}px)`
})
const imgA = computed(() => props.imgA)
const imgB = computed(() => props.imgB)
</script>
<style>
/* Tailwind handles layout; no extra CSS required. */
</style>
This is the main Vue file that uses the component. Copy-paste this into your project. In this code feel free to change anything you like, such as the component name, props, or class. This is the place where you control the main component.
<script setup></script>
<template>
<SectionsImageComparison
imgA="/images/placeholder1.jpg"
imgB="/images/placeholder2.jpg"
/>
</template>
Decide whether you want a global design-system or a one-off inline snippet.
Complete @theme
block – import once and share across every component.
Copy the code below into main.css
file. It is most likely in assets/css/main.css
directory.
:style
binding – paste straight onto any of ours components.
Copy the code below and paste it into the :style
binding of the component.
I wish I could automate every little thing—but for now you’ll need to handle these final steps by hand. Apologies for the extra work!
iq-card-*
style Now that you’ve picked a card preset, copy its CSS into your @layer components
block in main.css
. This ensures every `iq-card
` wrapper will look just right.
iq-cta
iq-cta is the main call to action button class. It’s used in many places across the components. But for now it is only a single class that you can customize. You can copy the code below and paste it into your @layer components
block in main.css
. In future you will be able to fully customize it from our UI and choose from many presets.
I didn't have time to figure out consistency. Although there are no actions required, be mindful that the forms might not be entirely consistent with the design system. A quick once-over will keep everything looking sharp.