Move scroll animation into flyout_base

This commit is contained in:
Eric Rosenbaum 2017-09-18 14:55:40 -04:00
parent 53101f763f
commit e494993e82
3 changed files with 23 additions and 38 deletions

View file

@ -544,6 +544,27 @@ Blockly.Flyout.prototype.recordCategoryScrollPositions_ = function() {
}
};
/**
* Step the scrolling animation by scrolling a fraction of the way to
* a scroll target, and request the next frame if necessary.
*/
Blockly.Flyout.prototype.stepScrollAnimation = function() {
if (!this.scrollTarget) {
return;
}
var scrollPos = this.horizontalLayout_ ?
-this.workspace_.scrollX : -this.workspace_.scrollY;
var diff = this.scrollTarget - scrollPos;
if (Math.abs(diff) < 1) {
this.scrollbar_.set(this.scrollTarget);
return;
}
this.scrollbar_.set(scrollPos + diff * 0.3);
// Polyfilled by goog.dom.animationFrame.polyfill
requestAnimationFrame(this.stepScrollAnimation.bind(this));
};
/**
* Delete blocks and background buttons from a previous showing of the flyout.
* @private