Recently, I came across and was intrigued by the "image slide effect" featured on their homepage.
The way the background image changes as you scroll up, leading you through different introductory slides before reaching the main content of the site caught my attention.
Out of curiosity and a desire to learn more about responsive web design, I attempted to replicate this effect. However, I've hit a roadblock and am unsure if my current approach is the best solution.
You can see how far I've gotten in this JSFiddle where I tried to recreate the image slider.
$(window).bind('mousewheel DOMMouseScroll', function(event){
if (event.originalEvent.wheelDelta > 0 || event.originalEvent.detail < 0) {
console.log('scrolling down');
}
else {
console.log('scrolling up');
$('.s1').slideUp('slow');
}
});
* { margin: 0; padding: 0 }
#menubar {
width: 100%;
background-color: orange;
height: 60px;
}
.slide {
position: absolute;
width: 100%;
top: 60px;
bottom: 0;
}
.slide.s1 { background-color: green; }
.slide.s2 { background-color: red; }
.slide.s3 { background-color: cornflowerblue; }
.l1 { z-index: 3; }
.l2 { z-index: 2; }
.l3 { z-index: 1; }
<script src="https://code.jquery.com/jquery-3.0.0.min.js"></script>
<html>
<body>
<header id="menubar"><p>hi im a header</p></header>
<section class="slide s1 l1"><p>im the first</p></section>
<section class="slide s2 l2"><p>im the second</p></section>
<section class="slide s3 l3"><p>im the third</p></section>
</body>
</html>
I initially set up three .slide
containers stacked on top of each other within the viewport, utilizing z-index
hierarchy and jQuery's .slideUp()
function to animate the topmost container's movement.
However, I'm uncertain if this method is ideal, especially when it comes to selecting the correct container to fade out.
Is there a simpler and possibly more modular approach to achieve this effect? Are there effective jQuery/CSS selectors to determine the currently visible topmost .slide
layer?