Skip to content

Instantly share code, notes, and snippets.

@hugeuser
Last active June 26, 2018 13:13
Show Gist options
  • Save hugeuser/9095183 to your computer and use it in GitHub Desktop.
Save hugeuser/9095183 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
});
@zzzbra
Copy link

zzzbra commented Aug 20, 2015

There are so many things missing from the code posted I assumed the author was trolling us, like, "haha figure it out yourselves dummies."

scrollThreshold is indeed missing and hence undefined. The author also doesn't explicitly state the relationship between the desktop and mobile code. Finally, perhaps the most obscene omission, he never defines slides or numSlides.

I've also found in toying around with the code supplied that the immediate functionality (once the above mentioned missing variables are defined and assigned) the behavior of the code isn't as discrete as what one finds up on the website. Instead I find a transform on height being applied that seldom finishes all the way, and when it does it usually trigger the transform on the subsequent slide. This might have to do with the fact that windowHeight was also left out and the way that I defined it.

Lastly I don't find the no-animation class to have any effect given either the supplied CSS or the script above. Would really like to know if the original author has anything they can offer the community given these omissions since they went to the trouble of posting the code in the first place.

@benrobertsonio
Copy link

It looks like there is a jQuery plugin inspired by this effect: https://github.com/alvarotrigo/pagePiling.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment