-
Notifications
You must be signed in to change notification settings - Fork 1
4. Easing functions
I think no point to explain what is the easing function. It's just applied to progress to speed up/slow down it
- Import easing functions from
easingsfolder. - Use
.easing()method
import NanoTween from 'nanotween'
import { backIn } from 'nanotween/easings'
// or
// import backIn from 'nanotween/easings/backIn'
const tween = new NanoTween()
.duration(1000)
.easing(backIn)To correctly reverse the tweening in points other than 0 or 1, we should know symmetrical reversed easing function.

Otherwise it causes unexpected changes on each .reverse()
I recommend you to read that article with explanation of emulating CSS timing functions with JavaScript.
If you want to add custom easing function, NanoTween requires it to have .reverse function inside to get reversed values from.
Example:
function backOut (k) {
var s = 1.70158
return --k * k * ((s + 1) * k + s) + 1
}
backOut.reverse = backIn
function backIn (k) {
var s = 1.70158
return k * k * ((s + 1) * k - s)
}
backIn.reverse = backOut
module.exports = backInNOTE: If no
.reverseis provided, NanoTween will use original function instead. This is done because fully symmetrical easing functions are equal with their reversed ones (all...InOutare symmetrical too).
Looks like that demo has all of these functions.
- backIn
- backInOut
- backOut
- bounceIn
- bounceInOut
- bounceOut
- circularIn
- circularInOut
- circularOut
- cubicIn
- cubicInOut
- cubicOut
- elasticIn
- elasticInOut
- elasticOut
- expoIn
- expoInOut
- expoOut
- linear
- quadraticIn
- quadraticInOut
- quadraticOut
- quarticIn
- quarticInOut
- quarticOut
- quinticIn
- quinticInOut
- quinticOut
- sinussoidalIn
- sinussoidalInOut
- sinussoidalOut