Created
February 14, 2019 20:59
-
-
Save m2paulc/92333dd6ecf036ef4803c2ca86ee71ca to your computer and use it in GitHub Desktop.
Mask 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
<section class="skewed" id="wrapper"> | |
<div class="layer bottom"> | |
<div class="content-wrap"> | |
<div class="content-body"> | |
<h1>Happy Halloween</h1> | |
</div> | |
<img src="https://res.cloudinary.com/dbpolimgc/image/upload/v1539199490/Mask%20Assets/Mask-bw.jpg" alt="mask negative"> | |
</div> | |
</div> | |
<div class="layer top"> | |
<div class="content-wrap"> | |
<div class="content-body"> | |
<h1>Trick or Treat</h1> | |
</div> | |
<img src="https://res.cloudinary.com/dbpolimgc/image/upload/v1539199490/Mask%20Assets/Mask-actual.jpg" alt="mask"> | |
</div> | |
</div> | |
<div class="handle"></div> | |
</section> |
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
document.addEventListener('DOMContentLoaded', function() { | |
let wrapper = document.getElementById('wrapper'); | |
let topLayer = wrapper.querySelector('.top'); | |
let handle = wrapper.querySelector('.handle'); | |
let skew = 0; | |
let delta = 0; | |
if(wrapper.className.indexOf('skewed') != -1) { | |
skew = 1000; | |
} | |
wrapper.addEventListener('mousemove', function(event) { | |
delta = (event.clientX - window.innerWidth / 2) * 0.5; | |
handle.style.left = event.clientX + delta + 'px'; | |
topLayer.style.width = event.clientX + skew + delta + 'px'; | |
}); | |
}); |
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
body { | |
margin: 0 | |
padding: 0 | |
font-size: 100%; | |
line-height: 1.6; | |
font-family: Helvetica, sans-serif; | |
} | |
#wrapper { | |
position: relative; | |
width: 100%; | |
min-height: 55vw; | |
overflow: hidden; | |
} | |
.layer { | |
position: absolute; | |
width: 100vw; | |
min-height: 55vw; | |
overflow: hidden; | |
} | |
.layer .content-wrap { | |
position: absolute; | |
width: 100vw; | |
min-height: 55vw; | |
} | |
.layer .content-body { | |
position: absolute; | |
width: 25%; | |
top: 50%; | |
text-align: center; | |
transform: translateY(-50%); | |
color: #fff; | |
} | |
.layer img { | |
position: absolute; | |
width: 35%; | |
top: 50%; | |
left: 50%; | |
transform: translate(-50%, -50%); | |
} | |
.layer h1 { | |
font-size: 2em; | |
} | |
.bottom { | |
background: #222; | |
z-index: 1; | |
} | |
.bottom .content-body { | |
right: 5%; | |
} | |
.bottom h1 { | |
color: #fdab00; | |
} | |
/* top layer */ | |
.top { | |
background: #eee; | |
color: #222; | |
z-index: 2; | |
width: 50vw; | |
} | |
.top .content-body { | |
left: 5%; | |
color: #222; | |
} | |
.handle { | |
position: absolute; | |
height: 100%; | |
display: block; | |
background-color: #fdab00; | |
width: 5px; /*for the bar*/ | |
top: 0; | |
left: 50%; | |
z-index: 3; | |
} | |
/* skew effect */ | |
.skewed .handle { | |
top: 50%; | |
transform: rotate(30deg) translateY(-50%); | |
height: 200%; | |
transform-origin: top; | |
} | |
.skewed .top { | |
transform: skew(-30deg); | |
margin-left: -1000px; | |
width: calc(50vw + 1000px); | |
} | |
.skewed .top .content-wrap { | |
transform: skew(30deg); | |
margin-left: 1000px; | |
} | |
@media(max-width: 768px) { | |
body { | |
font-size: 75%; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment