Skip to content

Instantly share code, notes, and snippets.

@ethagnawl
Forked from hugeuser/JavaScript
Last active August 29, 2015 14:22
Show Gist options
  • Save ethagnawl/e714a1b83504bba8c76a to your computer and use it in GitHub Desktop.
Save ethagnawl/e714a1b83504bba8c76a to your computer and use it in GitHub Desktop.
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