Skip to content

Instantly share code, notes, and snippets.

@alexeykomov
Created June 2, 2016 14:57
Show Gist options
  • Save alexeykomov/5181836ee013465bd85f825dac9a7a5e to your computer and use it in GitHub Desktop.
Save alexeykomov/5181836ee013465bd85f825dac9a7a5e to your computer and use it in GitHub Desktop.
Snap to bounds
rflect.ui.MomentumScroller.prototype.snapToBounds = function() {
const transition = rflect.browser.css.getSelectorCasedProperty('transform') +
' ' + 500 + 'ms ease-out';
this.setTransitionAll(transition);
// Different out of bounds cases:
// 1. If content is lower than frame upper border
if (this.contentOffsetY > 0) {
this.contentOffsetY = 0;
rflect.browser.css.setTransform(this.getScrollBarContainer(),
`translate3d(0, ${(this.getScrollBarLineHeight() / 2)}px, 0)`);
}
else {
// 2. If content is higher that frame lower border.
this.contentOffsetY = this.getLowestContentPosition();
rflect.browser.css.setTransform(this.getScrollBarContainer(),
`translate3d(0, ${this.frameElementSize.height -
this.getScrollBarLineHeight() / 2}px, 0)`);
}
rflect.browser.css.setTransform(this.element,
`translate3d(0, ${this.contentOffsetY}px, 0)`);
rflect.browser.css.setTransform(this.getScrollBarLine(),
`scaleY(${this.getScrollBarLineHeight()})`);
this.isDecelerating_ = true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment