Skip to content

Instantly share code, notes, and snippets.

@Julianhm9612
Forked from hugeuser/JavaScript
Created May 16, 2018 22:48
Show Gist options
  • Save Julianhm9612/f9c64875d764952e2dd5176c0b9779ad to your computer and use it in GitHub Desktop.
Save Julianhm9612/f9c64875d764952e2dd5176c0b9779ad to your computer and use it in GitHub Desktop.
"Scroll-Jacking" in Full Screen.
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