Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including react-compare-image with all npm packages installed. Try it out:

require("react/package.json"); // react is a peer dependency. require("react-dom/package.json"); // react-dom is a peer dependency. var reactCompareImage = require("react-compare-image")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

react-compare-image v1.1.0

React component to compare two images using slider.

React Compare Image

Simple React component to compare two images using slider.

img

NOTE: Vue.js Version is also available!

Demo

DEMO

Features

  • Simple
  • Responsive (fit to the parent width)
  • Size difference between two images handled correctly. Element size determined by following two factors:
    • width of the parent
    • right image's aspect ratio

How to use

yarn add react-compare-image

// or

npm install --save react-compare-image
import ReactCompareImage from 'react-compare-image';

<ReactCompareImage leftImage="image1.jpg" rightImage="image2.jpg" />;

Props

Prop (* required)typedefaultdescription
leftImage *stringnullleft image's url
rightImage *stringnullright image's url
sliderPositionPercentagenumber (float)0.5Default line position (from 0 to 1)
sliderLineWidthnumber (px)2line width of slider (by pixel)
sliderLineColorstring"#ffffff"line color of slider
leftImageCssobject{}Additional css for left image
rightImageCssobject{}Additional css for right image
leftImageLabelstringnullLabel for the image (e.g. before)
rightImageLabelstringnullLabel for the image (e.g. after)
handleSizenumber (px)40diameter of slider handle (by pixel)
hoverbooleanfalseWhether to slide at hover
skeletonelementnullElement displayed while image is loading
autoReloadSpannumber (ms)nullIf specified, the image is loaded again at the interval specified when loading images failed
autoReloadLimitnumber (count)10Limitation on automatic reload retry count
onSliderPositionChangefunctionnullCallback function called each time the slider changes. The position (0 to 1) of the slider is passed as arg

Dependencies

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free