JSFiddle - React, Tailwind, and code Playground
by lollero
HTML
<div class="diff-container">
<div class="before">
<img src="https://placeimg.com/640/480/animals/grayscale" alt="">
</div>
<div class="after">
<img src="https://placeimg.com/640/480/animals/grayscale" alt=""> </div>
</div>
<div class="diff-container">
<div class="before">
<img src="https://placeimg.com/640/480/animals/grayscale" alt="">
</div>
<div class="after">
<img src="https://placeimg.com/640/480/animals/grayscale" alt=""> </div>
</div>
CSS
.diff-container {
position: relative;
z-index: 0;
display: inline-block;
}
.diff-container img{
display: block;
}
.diff-container .after {
position: absolute;
z-index: 1;
top: 0;
left: 0;
overflow: hidden;
width: 0;
}
.diff-container .after img {
filter: blur(4px); // Just to differentiate the images from each other
}
JavaScript
$('.diff-container').each(function() {
$(this).on("mousemove", function( e ) {
var _this = $(this);
x = e.pageX - _this.offset().left,
y = e.pageY - _this.offset().top;
_this.find('.after').width( x ); // Vertical
});
});