Image Comparison slider

by guillaumedeplanque




npm version Dependency Status devDependency Status License


Compare two images in a slider with mouse move effect

Two kittens !


$ npm install image-comparison-slider


In your HTML file, create a block with the class "comparison-slider". Add two data-attributes :

  • data-image-width : the width of your two images
  • data-image-height : the height of your two images

Inside this block, add two divs like this :

<div class="comparison-slider" data-image-width=1157 data-image-height=851>
    <div class="before" style="background-image: url('img/before.jpg')"></div>
    <div class="after" style="background-image: url('img/after.jpg')"></div>

In your JS file, import the Comparison class & instantiate it :

import Comparison from 'image-comparison-slider';

const comparison = new Comparison();

Tadaaaaa ! Magic is done !

Demo mode

# Clone the repo
$ git clone

# Move into the repo
$ cd image-comparison-slider/

# Install dependencies
$ npm install

# Build assets for dev mode
$ npm run demo-build
# Build assets for production mode
$ npm run demo-build-prod

# Lauch the static server
$ node demo/server.js