Sat Mar 12 2022
0 views
3 min read
In this article, I will show you how to create a beautiful parallax landing page with jarallax.js.
You can find the source code and images from this repository on GitHub
I have already made a video about it on my youtube channel. Check that out.
Please like and subscribe to Cules Coding
<script src="https://unpkg.com/jarallax@2.0"></script>
<header class="header"><a class="logo" href="#">Parallax</a></header><section class="container"><div class="jarallax"><img class="jarallax-img" src="./media/1.webp" alt="" /><h2 class="text">Consectetur sunt</h2></div><div class="jarallax"><img class="jarallax-img" src="./media/2.webp" alt="" /><h2 class="text">Dolor odio.</h2></div><div class="jarallax"><img class="jarallax-img" src="./media/3.webp" alt="" /><h2 class="text">Adipisicing pariatur</h2></div><div class="jarallax"><img class="jarallax-img" src="./media/4.webp" alt="" /><h2 class="text">Consectetur accusamus?</h2></div><div class="jarallax"><img class="jarallax-img" src="./media/5.webp" alt="" /><h2 class="text">Ipsum deleniti?</h2></div></section>
Explanation:
@import url('https://fonts.googleapis.com/css2?family=Cousine:wght@700&display=swap');* {padding: 0;margin: 0;box-sizing: border-box;}html {font-size: 62.5%;}body {max-width: 100vw;overflow-x: hidden;background-color: #1b1b1b;font-family: 'Cousine', monospace;color: white;}.header {height: 10rem;display: flex;align-items: center;justify-content: space-between;padding: 0 5rem;}.logo {font-size: 3rem;font-weight: 700;color: white;letter-spacing: 0.1rem;text-decoration: none;}.container {width: 90vw;margin: 0 auto;display: grid;grid-row-gap: 5rem;padding: 10rem 0;}.jarallax {position: relative;display: grid;align-items: center;width: 100%;height: 100vw;max-height: 60rem;min-height: 40rem;}.text {z-index: 10;font-size: 3rem;text-transform: uppercase;margin-left: 10vw;}.jarallax:after {content: '';position: absolute;top: 0;left: 0;width: 100%;height: 100%;background-color: rgba(0, 0, 0, 0.1);}@media screen and (min-width: 600px) {.jarallax {max-height: 70rem;}.container {grid-row-gap: 8rem;}.text {font-size: 5rem;}}@media screen and (min-width: 1200px) {.jarallax {width: 90%;}.container {grid-row-gap: 15rem;width: 95vw;}.text {font-size: 7rem;}}
Explanation:
position: relative
.const jarallaxEls = document.querySelectorAll('.jarallax')jarallaxEls.forEach((el, index) => {if (index % 2) return falseel.style.justifySelf = 'end'})jarallax(jarallaxEls, {})
Explanation:
jarallax
function to create the parallax effect. The second parameter is an object which will contain the options. You can see the options in the documentation
.:nth-child(odd)
selector but it didn't work.justifySelf
property to all odd elements.Our final Result:
That's it for this article. I have tried to make it as simple as possible. If you have any questions, feel free to contact me.
© Copyright Cules Coding 2022