Assuming the following code (current state can be viewed here):
function scrollTopFromEvent(evt) {
return $(evt.target).scrollTop();
}
function scrollDirection(evt) {
return -evt.originalEvent.wheelDelta / 120 || evt.originalEvent.detail / 3;
}
function pageNumber(previous, next) {
return previous + next;
}
function scrollToPage(pageNumber) {
var container = $('.parallax');
TweenLite.to(container, 1, {
scrollTop: container.height() * (pageNumber)
});
}
function inRange(pageNumber) {
var totalPages = $('.parallax').find('div[id^="group"]').length;
return pageNumber >= 0 || pageNumber <= totalPages;
}
var scroll = $('.parallax')
.asEventStream('mousewheel DOMMouseScroll')
.doAction('.preventDefault').flatMap(scrollDirection);
var page = scroll
.scan(0, pageNumber)
.filter(inRange)
.log()
.onValue(scrollToPage);
I want to be able to limit the values emitted by the page
stream from 0 to n, n
being the totalPages
(defined in the inRange
method). In that particular case, there are 7 groups, so the range would be from 0 to 7
If a user scroll down to '7', and continues scrolling, no values would be emitted from the scroll stream.
Ideas?
Thanks