Live preview

Interactive example

Loading example…

Usage

Import the component and its manager, then make it your own.

ComponentImageSlider
Managercreate_image_slider_manager

svelte

<script>
  // Import the shared stylesheet once in your application's root layout.
  import "sveltekit-ui/style.css"
  import { ImageSlider, create_image_slider_manager } from "sveltekit-ui"

  // Inline artwork keeps this example independent of image hosting.
  const artwork = (sky) => "data:image/svg+xml," + encodeURIComponent(
    '<svg xmlns="http://www.w3.org/2000/svg" width="640" height="360" viewBox="0 0 640 360">' +
    '<rect width="640" height="360" fill="' + sky + '"/>' +
    '<circle cx="500" cy="90" r="42" fill="#fde68a"/>' +
    '<path d="M0 360 190 115 390 360ZM240 360 430 160 640 360Z" fill="#164e63"/></svg>'
  )

  const manager = create_image_slider_manager({
    src1: artwork("#94a3b8"),
    src2: artwork("#bae6fd"),
    percent_shown: 50,
    aria_label: "Compare original and edited sky",
  })
</script>

<div style="max-width: 64rem;">
  <ImageSlider {manager} />
</div>
<p>Drag the divider or focus it and use the arrow keys.</p>

API reference

Configure the manager, call its methods, and read its reactive state.

6 entries in configuration

PropertyTypeDefaultDescription
src1string nullurl for the first/base image
src2string nullurl for the second or 'comparison' image
color1string var(--primary-t)main color for the center dividing line and handle
color2string color-mix(in oklab, var(--primary-t), var(--bg) 80%)secondary color used to outline the dividing line or handle
percent_shownnumber 50initial percentage of how much of the second image is shown vs. the first
aria_labelstring or function Image comparisonAccessible name for the keyboard-operable image comparison slider.