A Pen by Marc Ucman on CodePen.
Created
July 22, 2019 06:42
-
-
Save beseidel/0dab0639a9c5d0d7f24522173365cfe8 to your computer and use it in GitHub Desktop.
CSS3 Split Screen Moving Slider
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 id="wrapper"> | |
<div class="layer left"> | |
<img src="https://upload.wikimedia.org/wikipedia/commons/d/d6/CathedralofLearningLawinWinter.jpg" alt="winter"/> | |
</div> | |
<div class="layer right"> | |
<img src="https://upload.wikimedia.org/wikipedia/commons/3/34/Rub_al_Khali_002.JPG" alt="desert"/> | |
</div> | |
<div class="handle"></div> | |
</div> |
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
document.addEventListener('DOMContentLoaded', function(){ | |
let wrapper = document.getElementById('wrapper'); | |
let topLayer = wrapper.querySelector('.left'); | |
let handle = wrapper.querySelector('.handle'); | |
let delta = 0; | |
wrapper.addEventListener('mousemove', function(e){ | |
delta = (e.clientX); | |
handle.style.left = e.clientX + 'px'; | |
topLayer.style.width= e.clientX + 'px'; | |
}); | |
}); |
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
body { | |
padding: 0; | |
margin: 0; | |
} | |
#wrapper { | |
position: relative; | |
width: 100%; | |
min-height: 70vw; | |
overflow: hidden; | |
} | |
.layer { | |
position: absolute; | |
width: 100vw; | |
min-height: 70vw; /* same as wrapper */ | |
max-height: 100%; | |
overflow: hidden; | |
} | |
.layer .content-body { | |
width: 25%; | |
position: absolute; | |
top: 50%; | |
text-align: center; | |
transform: translateY(-50%); | |
} | |
.layer img { | |
position: absolute; | |
top: 0; | |
left: 0; | |
height: 100%; | |
contain: cover; | |
} | |
.left { | |
background: #222; | |
z-index: 1; | |
} | |
.handle { | |
position: absolute; | |
height: 100%; | |
display: block; | |
background-color: blue; | |
width: 5px; | |
top: 0; | |
left: 50%; | |
z-index: 3; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment