Responsive Mobile-friendly Image Comparison Plugin - Images Compare

File Size: 533 KB
Views Total: 6184
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
Responsive Mobile-friendly Image Comparison Plugin - Images Compare

Images Compare is a responsive, touch-enabled jQuery image comparison plugin which enables the user to compare two images (after/before) with a slider. 

How to use it:

1. Load the required CSS file images-compare.css in the head section of the html document.

<link rel="stylesheet" href="images-compare.css">

2. Load jQuery library and the JavaScript file images-compare.js at the end of the html document.

<script src="//"></script>
<script src="jquery.images-compare.js"></script>

3. Load the hammer.js for touch events support.

<script src="hammer.min.js"></script>

4. Insert two images you want to compare into your webpage as follows:

<div class="js-img-compare">
  <div style="display: none;">
      <span class="images-compare-label">Before</span>
      <img src="before.jpg" alt="Before">
      <span class="images-compare-label">After</span>
      <img src="after.jpg" alt="After">

5. Active the image comparison plugin.


6. Configuration options with default values.


  // visible ratio of front element on init
  initVisibleRatio: 0.5,

  // "drag", "mousemove", "click"
  interactionMode: "drag", 

  // default animation duration in ms
  animationDuration: 400, 
  animationEasing: "swing",

  // add a html element on the separation
  addSeparator: true, 

  // add a html drag handle element on the separation
  addDragHandle: true, 

  // ratio precision, numbers after the decimal point
  precision: 4

7. API methods.

// call data('imagesCompare') to get the real object and not the jquery one
var test = $('.js-img-compare').imagesCompare().data('imagesCompare');

// show front image
test.setValue(1, true);

// shwo back image
test.setValue(0, true);

8. Events.

// call data('imagesCompare') to get the real object and not the jquery one
var test = $('.js-img-compare').imagesCompare().data('imagesCompare');

// fired when the value of visible front element is changed
test.on('change', function (event) {
  // ...

// fired when a resize window event has been received and treated
test.on('resize', function (event) {
  // ...

// fired when init is done
test.on('initialised', function (event) {
  // ...

Change logs:


  • Updated for jQuery 3+


  • Fixed: Nothing is visible after the init : Image calculations are done before images are loaded
  • Fixed: Labels are "floating" all around before the init
  • Added: Waiting for images to be loaded before calling the init function
  • Changed: Labels are hidden via css until the plugin add the wrapper class (initialised)


  • JS update.


  • Added tests, changed events name, string repeat polyfill added

This awesome jQuery plugin is developed by sylvaincombes. For more Advanced Usages, please check the demo page or visit the official website.