-
-
Save Julianhm9612/f9c64875d764952e2dd5176c0b9779ad to your computer and use it in GitHub Desktop.
"Scroll-Jacking" in Full Screen.
This file contains hidden or 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
var delta; | |
var currentSlideIndex = 0; | |
function elementScroll (e) { | |
// --- Scrolling up --- | |
if (e.originalEvent.detail < 0 || e.originalEvent.wheelDelta > 0) { | |
delta--; | |
if ( Math.abs(delta) >= scrollThreshold) { | |
prevSlide(); | |
} | |
} | |
// --- Scrolling down --- | |
else { | |
delta++; | |
if (delta >= scrollThreshold) { | |
nextSlide(); | |
} | |
} | |
// Prevent page from scrolling | |
return false; | |
} | |
function showSlide() { | |
// reset | |
delta = 0; | |
slides.each(function(i, slide) { | |
$(slide).toggleClass('active', (i >= currentSlideIndex)); | |
}); | |
} | |
function prevSlide() { | |
currentSlideIndex--; | |
if (currentSlideIndex < 0) { | |
currentSlideIndex = 0; | |
} | |
showSlide(); | |
} | |
function nextSlide() { | |
currentSlideIndex++; | |
if (currentSlideIndex > numSlides) { | |
currentSlideIndex = numSlides; | |
} | |
showSlide(); | |
} | |
$(window).on({ | |
'DOMMouseScroll mousewheel': elementScroll | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment