Last active
October 26, 2023 19:25
-
-
Save ZeldOcarina/d5817a7abb9157cbeaf5bdbb99ec10e7 to your computer and use it in GitHub Desktop.
HTML Before and Afters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="comparators"> | |
<div class="comparison"> | |
<figure | |
style=" | |
background-image: url(https://s3.amazonaws.com/cdn.monarchy.io/clients/nu-dentistry/before-after/b4a-1a.jpg); | |
" | |
> | |
<div | |
style=" | |
background-image: url(https://s3.amazonaws.com/cdn.monarchy.io/clients/nu-dentistry/before-after/b4a-1b.jpg); | |
" | |
id="divisor-1" | |
></div> | |
</figure> | |
<input | |
type="range" | |
min="0" | |
max="100" | |
value="50" | |
id="slider-1" | |
oninput="moveDivisor1()" | |
/> | |
</div> | |
<div class="comparison"> | |
<figure | |
style=" | |
background-image: url(https://s3.amazonaws.com/cdn.monarchy.io/clients/nu-dentistry/before-after/b4a-2a.jpg); | |
" | |
> | |
<div | |
id="divisor-2" | |
style=" | |
background-image: url(https://s3.amazonaws.com/cdn.monarchy.io/clients/nu-dentistry/before-after/b4a-2b.jpg); | |
" | |
></div> | |
</figure> | |
<input | |
type="range" | |
min="0" | |
max="100" | |
value="50" | |
id="slider-2" | |
oninput="moveDivisor2()" | |
/> | |
</div> | |
<div class="comparison"> | |
<figure | |
style=" | |
background-image: url(https://s3.amazonaws.com/cdn.monarchy.io/clients/nu-dentistry/before-after/b4a-3a.jpg); | |
" | |
> | |
<div | |
id="divisor-3" | |
style=" | |
background-image: url(https://s3.amazonaws.com/cdn.monarchy.io/clients/nu-dentistry/before-after/b4a-3b.jpg); | |
" | |
></div> | |
</figure> | |
<input | |
type="range" | |
min="0" | |
max="100" | |
value="50" | |
id="slider-3" | |
oninput="moveDivisor3()" | |
/> | |
</div> | |
</div> | |
<style> | |
.comparators { | |
display: flex; | |
gap: 2rem; | |
width: 1200px; | |
} | |
.comparison { | |
width: 60vw; | |
max-width: 600px; | |
max-height: 600px; | |
overflow: hidden; | |
aspect-ratio: 1 / 1; | |
} | |
.comparison figure { | |
/*background-image: url(https://s3.amazonaws.com/cdn.monarchy.io/clients/nu-dentistry/before-after/b4a-1a.jpg);*/ | |
background-size: cover; | |
position: relative; | |
font-size: 0; | |
width: 100%; | |
height: 100%; | |
margin: 0; | |
} | |
.comparison figure > img { | |
position: relative; | |
width: 100%; | |
} | |
.comparison figure div { | |
/*background-image: url(https://s3.amazonaws.com/cdn.monarchy.io/clients/nu-dentistry/before-after/b4a-1b.jpg);*/ | |
background-size: cover; | |
position: absolute; | |
width: 50%; | |
box-shadow: 0 5px 10px -2px rgba(0, 0, 0, 0.3); | |
overflow: hidden; | |
bottom: 0; | |
height: 100%; | |
} | |
input[type="range"] { | |
-webkit-appearance: none; | |
-moz-appearance: none; | |
position: relative; | |
top: -2rem; | |
left: -2%; | |
background-color: rgba(255, 255, 255, 0.1); | |
width: 102%; | |
} | |
input[type="range"]:focus { | |
outline: none; | |
} | |
input[type="range"]:active { | |
outline: none; | |
} | |
input[type="range"]::-moz-range-track { | |
-moz-appearance: none; | |
height: 15px; | |
width: 98%; | |
background-color: rgba(255, 255, 255, 0.1); | |
position: relative; | |
outline: none; | |
} | |
input[type="range"]::active { | |
border: none; | |
outline: none; | |
} | |
input[type="range"]::-webkit-slider-thumb { | |
-webkit-appearance: none; | |
width: 20px; | |
height: 15px; | |
background: #fff; | |
border-radius: 0; | |
} | |
input[type="range"]::-moz-range-thumb { | |
-moz-appearance: none; | |
width: 20px; | |
height: 15px; | |
background: #fff; | |
border-radius: 0; | |
} | |
input[type="range"]:focus::-webkit-slider-thumb { | |
background: rgba(255, 255, 255, 0.5); | |
} | |
input[type="range"]:focus::-moz-range-thumb { | |
background: rgba(255, 255, 255, 0.5); | |
} | |
</style> | |
<script> | |
const divisor1 = document.getElementById("divisor-1"); | |
const slider1 = document.getElementById("slider-1"); | |
const divisor2 = document.getElementById("divisor-2"); | |
const slider2 = document.getElementById("slider-2"); | |
const divisor3 = document.getElementById("divisor-3"); | |
const slider3 = document.getElementById("slider-3"); | |
function moveDivisor1() { | |
divisor1.style.width = slider1.value + "%"; | |
} | |
function moveDivisor2() { | |
divisor2.style.width = slider2.value + "%"; | |
} | |
function moveDivisor3() { | |
divisor3.style.width = slider3.value + "%"; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment