Skip to content

Instantly share code, notes, and snippets.

@jamesplease
Created February 24, 2019 06:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesplease/68f6c50d77463efc0d962dd9f0ef2962 to your computer and use it in GitHub Desktop.
Save jamesplease/68f6c50d77463efc0d962dd9f0ef2962 to your computer and use it in GitHub Desktop.
if (changeInY > 0 && restraints.down !== null) {
const dampFactor =
1 -
linearScale({
domain: [0, restraints.down * 2],
range: [0, 0.5],
value: changeInY,
});
let dampedChangeInY = changeInY * dampFactor;
if (dampedChangeInY > restraints.down) {
dampedChangeInY = restraints.down;
}
changeInY = dampedChangeInY;
} else if (changeInY < 0) {
if (typeof restraints.up === 'number') {
const dampFactor =
1 -
linearScale({
domain: [0, -restraints.up * 2],
range: [0, 0.5],
value: changeInY,
});
let dampedChangeInY = changeInY * dampFactor;
if (dampedChangeInY < -restraints.up) {
dampedChangeInY = -restraints.up;
}
changeInY = dampedChangeInY;
} else if (restraints.up === 'drag') {
const absoluteChange = Math.abs(changeInY);
changeInY = -Math.pow(absoluteChange, 0.7);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment