Image filter
by Kevin Pliester
HTML
<div class="container">
<div class="image-slider">
<div class="image-1"></div>
<div class="image-2"></div>
<input type="range" min="1" max="100" value="50" class="slider">
</div>
</div>
SCSS
.container {
position: relative;
max-width: 600px;
margin: 5% auto;
}
.image-slider {
position: relative;
width: 100%;
height: 400px;
display: block;
background: red;
.image-1 {
overflow: hidden;
position: absolute;
z-index: 1;
height: 100%;
width: 100%;
background-image: url('http://lenawenz.de/wp-content/uploads/2018/03/182803-homepagefotos-013_preview.jpeg');
background-size: auto;
background-attachment: fixed;
background-repeat: no-repeat;
background-position: center;
}
.image-2 {
overflow: hidden;
position: absolute;
z-index: 2;
height: 100%;
width: 0%;
background-image: url('http://lenawenz.de/wp-content/uploads/2018/03/182803-homepagefotos-013_preview.jpeg');
background-size: auto;
background-attachment: fixed;
background-repeat: no-repeat;
background-position: center;
-webkit-filter: grayscale(100%);
filter: gray;
&:after {
content: '';
position: absolute;
height: 100%;
border: 1px solid rgba(0, 0, 0, .5);
right: 1px;
top: 0;
}
}
.slider {
position: absolute;
z-index: 3;
top: 50%;
left: calc( 50% + 1px );
transform: translate(-50%, -50%);
max-width: 900px;
}
}
.slidecontainer {
width: 100%;
}
.slider {
-webkit-appearance: none;
appearance: none;
width: 100%;
height: 100%;
background: transparent;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
}
.slider:hover {
opacity: 1;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 10px;
height: 50px;
background: white;
cursor: pointer;
border-radius: 3px;
}
.slider::-moz-range-thumb {
width: 10px;
height: 50px;
background: white;
border: 2px solid rgba(0, 0, 0, .05);
cursor: pointer;
border-radius: 5px;
}
JavaScript
(function($) {
$('.image-2').css({
'width': $('.slider').val() + '%'
});
$('.slider').on('change input', function() {
$('.image-2').css({
'width': $(this).val() + '%'
});
});
})(jQuery)