Browse Source

- Fixing a bug with the timing of the final setting of the vertical scroll position (#3508)

jittering-top
Ian Oberst 7 years ago
committed by Yotam Berkowitz
parent
commit
006b1625e9
1 changed files with 19 additions and 13 deletions
  1. +19
    -13
      lib/timeline/Timeline.js

+ 19
- 13
lib/timeline/Timeline.js View File

@ -428,32 +428,38 @@ Timeline.prototype.focus = function(id, options) {
} }
}; };
// Perform one last check at the end to make sure the final vertical
// position is correct
var finalVerticalCallback = function() {
// Enforces the final vertical scroll position
var setFinalVerticalPosition = function() {
var finalVerticalScroll = getItemVerticalScroll(me, item); var finalVerticalScroll = getItemVerticalScroll(me, item);
if(finalVerticalScroll.shouldScroll && finalVerticalScroll.itemTop != initialVerticalScroll.itemTop) {
if (finalVerticalScroll.shouldScroll && finalVerticalScroll.itemTop != initialVerticalScroll.itemTop) {
me._setScrollTop(-finalVerticalScroll.scrollOffset); me._setScrollTop(-finalVerticalScroll.scrollOffset);
me._redraw();
me._redraw();
} }
}; };
// Perform one last check at the end to make sure the final vertical
// position is correct
var finalVerticalCallback = function() {
// Double check we ended at the proper scroll position
setFinalVerticalPosition();
// Let the redraw settle and finalize the position.
setTimeout(setFinalVerticalPosition, 100);
};
// calculate the new middle and interval for the window // calculate the new middle and interval for the window
var middle = (start + end) / 2; var middle = (start + end) / 2;
var interval = Math.max((this.range.end - this.range.start), (end - start) * 1.1);
var interval = Math.max(this.range.end - this.range.start, (end - start) * 1.1);
var animation = (options && options.animation !== undefined) ? options.animation : true;
var animation = options && options.animation !== undefined ? options.animation : true;
if(!animation) {
if (!animation) {
// We aren't animating so set a default so that the final callback forces the vertical location // We aren't animating so set a default so that the final callback forces the vertical location
initialVerticalScroll = {shouldScroll: false, scrollOffset: -1, itemTop: -1};
initialVerticalScroll = { shouldScroll: false, scrollOffset: -1, itemTop: -1 };
} }
this.range.setRange(middle - interval / 2, middle + interval / 2, { animation: animation }, finalVerticalCallback, verticalAnimationFrame);
// Let the redraw settle and finalize the position
setTimeout(finalVerticalCallback, 100);
this.range.setRange(middle - interval / 2, middle + interval / 2, { animation: animation }, finalVerticalCallback, verticalAnimationFrame);
} }
}; };

Loading…
Cancel
Save