This is a vanilla javascript component to compare two images with a slider. Inspired from CodyHouse’s jQuery plugin
npm i @armino-dev/comparing-slider
Import the components into your script.
import ComparingSlider from '@armino-dev/comparing-slider';
Import the css into your stylesheet.
import '@armino-dev/comparing-slider/dist/comparing-slider.min.css';
<script type="module" src="node_modules/@armino-dev/comparing-slider/dist/comparing-slider.min.js"></script>
<link rel="stylesheet" href="node_modules/@armino-dev/comparing-slider-dialog/dist/comparing-slider.min.css" />
<script type="module" src="https://esm.sh/@armino-dev/comparing-slider/dist/comparing-slider.min.js"></script>
<link rel="stylesheet" href="https://esm.sh/@armino-dev/comparing-slider/dist/comparing-slider.min.css" />
const options = {
// the container id where the code will be rendered
containerId: 'container1',
left: {
image: '//path/to/the/image',
alt: 'Some alternative text'
},
right: {
image: '//path/to/the/image',
alt: 'Some alternative text'
}
};
document.addEventListener("DOMContentLoaded", () => {
new ComparingSlider(options); // if using es6 import style
// or createComparingSlider(options) // if using cdn/local script into html
});
Demo can be viewed on here
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update the specs(tests) as appropriate.