I have this code:
(The code should send the user to a div with the class "scroll". Every time the user is scrolling, it sends to the next (or previous) div with class "scroll")
(function ($) {
var targets = $('.scroll'); // List of elements to scroll to
var index = 0;
// Modulo function which also works with negative numbers:
function mod(x, n) {
return x - (n * Math.floor(x / n));
}
$(window).mousewheel(function (ev) {
if (ev.deltaY < 0) {
index = index + 1; // Scrolling up, so increase index
} else {
index = index - 1; // Scrolling down, so decrease index
}
// Make sure the index is between 0 and (targets.length - 1)
index = mod(index, targets.length);
// Scroll to the target element:
$(window).scrollTo(targets.get(index), {
duration: 500,
easing: 'swing'
});
});
})($);
I have already added ScrollTo (min) 1.4.2, MouseWheel 3.1.13 and jQuery (min) 1.7.2 to the project. I have also added a "scroll" class to all my divs where I want it to scroll.
But it doesn't seem to work.
I took this code from http://ift.tt/1UGjaGo (optimized for my own needs with bla bla for testing). The problem with this code is that it add a "current" class to every next div, what I want, is it so send the user to a specific div (with class named "scroll"). I replaced the JS in jsfiddle with the code I got from a question I asked before. Tried to optimize it but it's still not working.
You may fix the code above to fit the code from jsfiddle or optimize the code in jsfiddle. Maybe jsfiddle code would be even better since it's working well.
If you can help you will save me. Really, I already spent like 13 hours searching.
Thank you
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire