Uses customised range input for slider. More details on my blog
Forked from anonymous/html5-before-after-comparison-slider.markdown
Last active
August 29, 2016 19:09
-
-
Save gfrice/b4d8908d2bfeb5bb4545982e5c2f079e to your computer and use it in GitHub Desktop.
HTML5 Before & After Comparison Slider
This file contains 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 id="comparison"> | |
<figure> | |
<div id="divisor"></div> | |
</figure> | |
<input type="range" min="0" max="100" value="50" id="slider" oninput="moveDivisor()"> | |
</div> |
This file contains 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
var divisor = document.getElementById("divisor"), | |
slider = document.getElementById("slider"); | |
function moveDivisor() { | |
divisor.style.width = slider.value+"%"; | |
} |
This file contains 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
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> |
This file contains 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#comparison { | |
width: 60vw; | |
height: 60vw; | |
max-width: 600px; | |
max-height: 600px; | |
overflow: hidden; } | |
div#comparison figure { | |
background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/photoshop-face-before.jpg); | |
background-size: cover; | |
position: relative; | |
font-size: 0; | |
width: 100%; | |
height: 100%; | |
margin: 0; | |
} | |
div#comparison figure > img { | |
position: relative; | |
width: 100%; | |
} | |
div#comparison figure div { | |
background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/photoshop-face-after.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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment