mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-22 05:21:52 +08:00
fix(scroll): correctly resolve when scrolling finishes
This commit is contained in:
@ -56,11 +56,16 @@ export class ScrollView {
|
|||||||
|
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
let startTime: number;
|
let startTime: number;
|
||||||
|
let attempts = 0;
|
||||||
|
|
||||||
// scroll loop
|
// scroll loop
|
||||||
function step() {
|
function step() {
|
||||||
if (!self._el || !self.isPlaying) {
|
attempts++;
|
||||||
return resolve();
|
|
||||||
|
if (!self._el || !self.isPlaying || attempts > 200) {
|
||||||
|
self.isPlaying = false;
|
||||||
|
resolve();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let time = Math.min(1, ((Date.now() - startTime) / duration));
|
let time = Math.min(1, ((Date.now() - startTime) / duration));
|
||||||
@ -74,10 +79,10 @@ export class ScrollView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (fromX != x) {
|
if (fromX != x) {
|
||||||
self._el.scrollLeft = Math.round((easedT * (x - fromX)) + fromX);
|
self._el.scrollLeft = Math.floor((easedT * (x - fromX)) + fromX);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (time < 1 && self.isPlaying) {
|
if (easedT < 1) {
|
||||||
raf(step);
|
raf(step);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user