I need to write a iscroll with infinite loop,
let the height of full range of the element is scrollPeriod
I have to scroll back by 1 ~ 2 times scrollPeriod( with the elements is extend to 5 times, either top or bottom has at least 2 times' cushion),
it looks like this:
_this.monthScroll.on("scrollEnd", function () {
var currentScrollPos = this.y;
var moved = currentScrollPos - startY;
if (Math.abs(moved) > scrollPeriod) {
var ratio = Math.round(Math.abs(moved) / scrollPeriod);
this._tobeMoved = moved > 0 ? -scrollPeriod : scrollPeriod;
this.scrollBy(0, this._tobeMoved * ratio);
}
var target = lis[-(Math.round(this.y * totalSize / totalHeight)) + 2];
_this.selectedMonth = new Number(target.innerHTML) - 1;
_this.renderDate();
});
and my problem is:
when I initial the scroller first time, I set options.startY to a calculated startY, then IScroll wiill scroll to startY in constructor, but without updating currentPage,
currentPage also won't update when I scrollBy(0, this._tobeMoved * ratio)
thus, until the currentPage.y first time to be in a range of [startY - scrollPeriod , startY + scrollPeriod], the snap could perform rightly.
before it's first time to be in [startY - scrollPeriod , startY + scrollPeriod], snap will always snap to the element that close to first element(before snap, i have already scrolled it to another coupled copy of it which is near the middle, and it will snap to the first copy near top).
so I think, if we should let scrollTo or _translate method to update currentPage and allow people to initial the scroller by something like options.startPageY, and add an api like scrollToPage(pageX,pageY,time,easing) so that snap could perform rightly with a customed start position?
additionally,
I find IScroll's momentum is extremely fast on some android phone, I solve it by overwrite IScroll.utils.momentum so I think IScroll should provide an option to customize the process of calculating distance/speed so that people can deal with some compatibility issue.
I need to write a iscroll with infinite loop, let the height of full range of the element is scrollPeriod I have to scroll back by 1 ~ 2 times scrollPeriod( with the elements is extend to 5 times, either top or bottom has at least 2 times' cushion), it looks like this:
and my problem is: when I initial the scroller first time, I set options.startY to a calculated startY, then IScroll wiill scroll to startY in constructor, but without updating currentPage, currentPage also won't update when I scrollBy(0, this._tobeMoved * ratio) thus, until the currentPage.y first time to be in a range of [startY - scrollPeriod , startY + scrollPeriod], the snap could perform rightly. before it's first time to be in [startY - scrollPeriod , startY + scrollPeriod], snap will always snap to the element that close to first element(before snap, i have already scrolled it to another coupled copy of it which is near the middle, and it will snap to the first copy near top).
so I think, if we should let scrollTo or _translate method to update currentPage and allow people to initial the scroller by something like options.startPageY, and add an api like scrollToPage(pageX,pageY,time,easing) so that snap could perform rightly with a customed start position?
additionally, I find IScroll's momentum is extremely fast on some android phone, I solve it by overwrite IScroll.utils.momentum so I think IScroll should provide an option to customize the process of calculating distance/speed so that people can deal with some compatibility issue.