Skip to content

lemon3/slick-image-compare

Repository files navigation

MIT License

slick image compare

Is a modern image comparison slider written in vanilla JavaScript and has no dependencies on other libraries. Best for comparing images, image retouching, color adjustments, renderings, etc... It uses the requestAnimationFrame api for rendering.

(Started as a jQuery-Plugin back in the days (2013) and was used for a custom WordPress-Plugin)

Use it with

Vanilla JS React Astro
vanilla js react astro
vanilla JS react component astro component
The core JS library A React wrapper An Astro wrapper

Docs

Read the documentation >>

Preview

demo

Example

Vanilla js

vanilla js

module:

pnpm add slick-image-compare
<div id="my-div"></div>
import SlickImageCompare from 'slick-image-compare';
import 'slick-image-compare/style';

const options = {
  beforeImage: 'before.jpg',
  afterImage: 'after.jpg',
};

const sic = new SlickImageCompare('#my-div', options);

classic:

<link rel="stylesheet" href="https://unpkg.com/slick-image-compare/dist/slick-image-compare.css">
<script src="https://unpkg.com/slick-image-compare"></script>

<div id="my-div" style="max-width=640px">
  <img src="before.jpg" alt="before image" />
  <img src="after.jpg" alt="after image" />
</div>

<script>
  const sic = new SlickImageCompare('#my-div');
</script>

more info goto core package (vanilla js)!

React

react js

pnpm add slick-image-compare-react
import React from 'react';
import SlickImageCompare from 'slick-image-compare-react';
import 'slick-image-compare/style';

function App() {
  const options = {
    beforeImage: '01_before.png',
    afterImage: '01_before.png',
  };

  return (
    <>
      {/* 1) use with the defined option object */}
      <SlickImageCompare options={options} />

      {/* 2) use with img child nodes and default settings */}
      <SlickImageCompare>
        <img src="01_before.png" alt="before" />
        <img src="01_after.png" alt="after" />
      </SlickImageCompare>
    </>
  );
}

export default App;

more info goto the react component package!