Skip to content

Instantly share code, notes, and snippets.

@bogoslavskiy
Created July 8, 2018 20:10
Show Gist options
  • Save bogoslavskiy/c36a189e08968bec1949ad2895fd53e9 to your computer and use it in GitHub Desktop.
Save bogoslavskiy/c36a189e08968bec1949ad2895fd53e9 to your computer and use it in GitHub Desktop.
_handleIntermediateState = (scrollToOffset) => {
let scrollY = this.scrollY._value;
if(scrollY < this.topPartHeight) { // Full
scrollToOffset(scrollY > (this.topPartHeight / 2) ? this.topPartHeight : 0);
} else { // Clamped
if(
this._clampedScrollValue < this.maxClamp &&
this._clampedScrollValue > this.minClamp
) {
let scrollTo;
if(this._clampedScrollValue > (this.maxClamp + this.minClamp) / 2) {
scrollTo = scrollY + this._interpolate(
this._clampedScrollValue,
[this.maxClamp, this.minClamp],
[0, this.diffClamp]
);
} else {
scrollTo = scrollY - this._interpolate(
this._clampedScrollValue,
[this.minClamp, this.maxClamp],
[0, this.diffClamp]
);
}
scrollToOffset(scrollTo);
}
}
}
_interpolate = (x, inputRange, outputRange) => {
let minX = inputRange[0];
let maxX = inputRange[1];
let minY = outputRange[0];
let maxY = outputRange[1];
return (x - minX) * ((maxY - minY) / (maxX - minX) + minY);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment