Home

Awesome

react-before-after-slider (demo)

A sexy image comparison slider for React.

NPM Build Status JavaScript Style Guide

This component is perfect for displaying the differences between two images, allowing the user to slide over them for an enticing before & after reveal effect.

Install

npm install --save react-before-after-slider

Usage

Check out the demo.

import React, { Component } from 'react'

import BeforeAfterSlider from 'react-before-after-slider'

class Example extends Component {
  render () {
    const before = 'https://...example1.jpg'
    const after = 'https://...example2.jpg'

    return (
      <BeforeAfterSlider
        before={before}
        after={after}
        width={640}
        height={480}
      />
    )
  }
}

Props

PropertyTypeDefaultDescription
beforestringRequiredURL of before image to use.
afterstringRequiredURL of after image to use.
widthnumberRequiredWidth in pixels for the component.
heightnumberRequiredHeight in pixels for the component.
defaultProgressnumber0.5Where the progress slider should start (float between 0 and 1).
classNamestringClass name to add to root div element.
beforeClassNamestringClass name to add to before element.
afterClassNamestringClass name to add to after element.
beforePropsobject{ }Optional extra props to pass to the before BlockImage.
afterPropsobject{ }Optional extra props to pass to the after BlockImage.
......undefinedAny other props are applied to the root div element.

Note that by default, both before and after will be displayed as background images with background-size: cover via react-block-image.

Todo

Related

License

MIT © transitive-bullshit

Support my OSS work by <a href="https://twitter.com/transitive_bs">following me on twitter <img src="https://storage.googleapis.com/saasify-assets/twitter-logo.svg" alt="twitter" height="24px" align="center"></a>