Created
December 12, 2018 00:24
-
-
Save cluzier/7c1daee5311624f4bb880be2c352d044 to your computer and use it in GitHub Desktop.
Parallax Practice
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="parallax-container"> | |
<div style="background-image: url(https://cdn2.hubspot.net/hubfs/1951013/Parallax/SkyBG.png);"> | |
</div> | |
<div style="background-image: url(https://cdn2.hubspot.net/hubfs/1951013/Parallax/Clouds1.png);"> | |
</div> | |
<div style="background-image: url(https://cdn2.hubspot.net/hubfs/1951013/Parallax/Clouds2.png);"> | |
</div> | |
<div style="background-image: url(https://www.superrb.com/frontend/img/parallax/mountains-foreground-layer-6.png);"> | |
</div> | |
<div class="mountains" style="background-image: url(http://plasticdetox.me/static/media/bg6.8ab073ae.png)";> | |
</div> | |
<div style="background-image: url(http://www.firewatchgame.com/images/parallax/parallax8.png)";> | |
</div> | |
</div> | |
<div id="content"> | |
<h1>Parallax Effect</h1> | |
<p>the effect whereby the position or direction of an object appears to differ when viewed from different positions, e.g., through the viewfinder and the lens of a camera.</p> | |
</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
window.addEventListener('scroll', () => { | |
let parent = document.getElementById('parallax-container'); | |
let children = parent.getElementsByTagName('div'); | |
for(let i = 0; i < children.length; i++) { | |
children[i].style.transform = 'translateY(-' + (window.pageYOffset * i / children.length) + 'px)'; | |
} | |
}, false) |
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
@import url('https://fonts.googleapis.com/css?family=Markazi+Text|Raleway'); | |
body { | |
margin: 0; | |
background: rgb(33,0,2); | |
} | |
#parallax-container { | |
display: block; | |
height: 95vmin; | |
} | |
#parallax-container div { | |
position: fixed; | |
top: 0; | |
background-position: center top; | |
background-size: cover; | |
transform: translateY(0vmin); | |
height: 95vmin; | |
width: 100%; | |
} | |
#content { | |
position: relative; | |
background: rgb(33,0,2); | |
color: #ffffff; | |
padding: 30vmin; | |
} | |
#content h1 { | |
font-size: 15vmin; | |
text-align: center; | |
font-family: 'Markazi Text', serif; | |
} | |
#content p { | |
font-size: 3vmin; | |
font-family: 'Raleway', sans-serif; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment