A Pen by Brett McCaffray on CodePen.
Created
May 23, 2019 12:48
-
-
Save CodeMyUI/c0e1124c9b5838f1cbbf1e92f9c9fc32 to your computer and use it in GitHub Desktop.
Background Mouse-Position 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
#banner-wrapper.banner-wrapper | |
.banner.design | |
.banner-content | |
%img{:src => 'https://goo.gl/L35vUt'} | |
.banner.dev | |
.banner-content | |
%img{:src => 'https://goo.gl/JDWFxe'} |
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 banner = document.getElementById('banner-wrapper'); | |
let devLayer = banner.querySelector('.dev'); | |
let delta = 0; | |
banner.addEventListener('mousemove', function(e){ | |
delta = (e.clientX - window.innerWidth / 2) * 0.5; | |
devLayer.style.width = e.clientX + 500 + 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; | |
.banner-wrapper { | |
position: relative; | |
width: 100%; | |
height: 400px; | |
overflow: hidden; | |
} | |
.banner { | |
position: absolute; | |
overflow: hidden; | |
&.dev { | |
transform: skew(-30deg); | |
margin-left: -500px; | |
width: calc(50vw + 500px); | |
.banner-content { | |
transform: skew(30deg); | |
margin-left: 500px; | |
} | |
} | |
.banner-content { | |
height: 400px; | |
} | |
img { | |
width: 100vw; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment