So, I bind a function to window scroll, but it runs repeatedly when user scrolls.
But I want it to run once when user scrolls, and when the scroll ends, then when user scrolls again I want it to run again.
Right now my code looks like this:
function whenScroll() {
var zSection = $(".zSection").toArray();
if (window.calc == -1) {
$(zSection[window.zSecPos]).stop().slideToggle();
} else {
$(zSection[window.zSecPos-1]).stop().slideToggle();
}
clearTimeout($.data(this, "scrollTimer"));
$.data(this, "scrollTimer", setTimeout(function() {
if (window.calc == -1) {
window.zSecPos = window.zSecPos + 1;
} else {
window.zSecPos = window.zSecPos - 1;
}
}, 250));
}
window.zSecPos = 0;
$(window).scroll(function() {
whenScroll();
});
By the way, window.calc indicates the scroll direction, which I determine in another js file.