Created
July 8, 2018 20:10
-
-
Save bogoslavskiy/c36a189e08968bec1949ad2895fd53e9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_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