In this project, we are going to create an image slider with which we can check 2 images. If we are making an exact copy of them. We can compare every single boundary of the first image with the second image in both the vertical and horizontal directions.
- Create an HTML file in which we are going to add the main div, further we are adding two div’s in it for adding images in them.
- Create a CSS file to add images in the respective div.
- Firstly, create an HTML file (index.html).
- Now after the creation of our HTML file, we are going to give a title to our webpage using the <title> tag. It should be placed between the <head> tag.
- Then we link the CSS file that provides all the background images to our HTML. This is also placed in between the <head> tag.
- Coming to the body section of our HTML code.
- Firstly, create a main div as the main box.
- In that div, add 2 more divs to add image 1 and image 2.
CSS Code: The following is the content for the “style.css” file used in the above code. CSS is used to give different types of animations and effects to our HTML page so that it looks interactive to all the users. Consider the following points.
- Restore all the browser effects.
- Use classes and ids to give effects to HTML elements.
- Detection of mouse movement for movement of images.
- Use of different keyboard keys in event listeners for vertical and horizontal movement.
document.querySelector('css_selector') => returns the first element that matches with specified CSS selector.
Guide for the vertical and horizontal movement
- Default horizontal movement of the slider.
- Vertical movement is active when the user presses the (v) key once.
- Horizontal movement is active again when the user presses the (h) key once.
Note: The v and h are only valid in a small case.
The following is the content for “index.js” file used in the above HTML code.
Output: In this way, you can compare your 2 images together.