I have a few sections (each of size 100% x 100% - Fullscreen), which are fixed and overlapped on top of one another using z-index. I want to detect the mouse scroll and display respective sections using jQuery (Basically, something like fullpage.js but I will have different animations). I read many questions and tried the following code, but doesn't work.
Javascript:
$(document).ready(function(){
sections=["intro","features","gallery","contact"]
cs=0;
$(window).on('mousewheel DOMMouseScroll', function(e){
if(e.originalEvent.detail > 0) {
//scroll down - Show next section
if(cs < (sections.length-1)){
$("#"+sections[cs]).fadeOut();
cs+=1;
$("#"+sections[cs]).fadeIn();
}
}
else{
//scroll up - Show previous section
if(cs > 0){
$("#"+sections[cs]).fadeOut();
cs-=1;
$("#"+sections[cs]).fadeIn();
}
}
return false;
});
});
HTML:
<section id="intro">
<div class="content">
<h1>Intro</h1>
</div>
</section>
<section id="features">
<div class="content">
<h1>Features</h1>
</div>
</section>
<section id="gallery">
<div class="content">
<h1>Gallery</h1>
</div>
</section>
<section id="contact">
<div class="content">
<h1>Contact Us</h1>
</div>
</section>
To see the whole code, in case you need it, visit github