jquery image comparison slide

How we can create a compare slider for the image using JS or any JS library? Solution: Check out this Image Comparison Slide Using jQuery and CSS, Image Compare Slider.

Previously I have shared a Before and After Image slider, this is also similar to that but it is an advanced one and it’s based on jQuery. Basically, an image comparison slider used for comparing two images using a splitter slide handle. It helps to compare before/after or original/modified images easily. This type of compare slider used on editing websites and image compress websites.

Today you will learn to create an Image Compare Slider. Basically, there is a box with two images, a slider handle, and some texts. Middle of the box, there is placed the slider handle for drag and slide. On the left side this is a modified image with text “modified” and on the right side is the original image with text “original”. When when will drag handle and start slide then on part’s width will increase according to your slider direction.

So, Today I am sharing Image Comparison Slide Using jQuery and CSS. There I have used CSS for styling and jQuery for functioning, also jQuery modified CSS values to execute the result on the action. This is a complete program and ready to use on any kind of website. You can use this program after image modification or backend integration.

If you are thinking now how this image compares slider actually is, then see the preview given below.

Preview Of Image Compare Slider

See this video preview to getting an idea of how this comparing slider looks like.

Live Demo

Now you can see this program visually, Also you can see it live by pressing the button given above. If you like this, then get the source code of its.

You May Also Like:

Image Comparison Slide Using jQuery and CSS Source Code

Before sharing source code, let’s talk about it. First I have created a figure using HTML <figure> tag and placed all elements inside the tag. Inside the figure tag, I have placed an IMG tag for the original image, a span for text, a div with span for modified image and text, and another span to place the handle. Also in the HTML file, I have linked other files like CSS, JS, and jQuery CDN.

Now using CSS I have placed all the items in the right place, as you can see in the preview. For placing the second modified image and the slider handle I have used CSS background-image: command and gave IMG URL. There I have used transition command for smooth animation effects. And used CSS @keyframe command to create the animation effects.

jQuery handling here all features of the program by modifying HTML and CSS values dynamically. I have used HTML Data-* attribute to store custom data and pass in the JS file. There I have used JS if{} else{} commands and adding/removing CSS class names according to action. Also, I have used jQuery dragElement and resizeElement commands to create the program.

Left all other things you will understand after getting the codes, I can’t explain all in writing. For creating this program you have to create 3 files. First file for HTML, second file for CSS, and the third file for JavaScript. Follow the steps to creating this program without any error.

index.html

Create an HTML file named ‘index.html‘ and put these codes given here.

style.css

Now create a CSS file named ‘style.css‘ and put these codes given here.

function.js

The final step, create a JavaScript file named ‘function.js‘ and put the codes.

That’s It. Now you have successfully created Image Comparison Slide Using jQuery and CSS, Image Compare Slider. If you have any doubt or question comment down below.

Thanks For Visiting, Keep Visiting.

2 COMMENTS

  1. hey!
    I’ve tried it. It’s an amazing slider but unfortunately, it doesn’t work on mobile (tried on android).
    Is it me or it’s because of the code that is just not able to work on mobile?

    Kindly

LEAVE A REPLY

Please enter your comment!
Please enter your name here