Last active
June 26, 2018 13:13
-
-
Save hugeuser/9095183 to your computer and use it in GitHub Desktop.
"Scroll-Jacking" in Full Screen.
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
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
And a tutorial: https://onextrapixel.com/how-to-create-a-beautiful-fullscreen-single-scrolling-page-like-huge-inc/