Skip to content

Instantly share code, notes, and snippets.

@pomle
Last active March 7, 2018 10:25
Show Gist options
  • Save pomle/9c917229023c14ce1654f5ca78a8bf93 to your computer and use it in GitHub Desktop.
Save pomle/9c917229023c14ce1654f5ca78a8bf93 to your computer and use it in GitHub Desktop.
function between(subject, options = {}) {
const {rigidity, alias} = Object.assign({
rigidity: 10,
alias: new Map(),
}, options);
const keys = Object.keys(subject);
let last = Object.assign({}, subject);
let intended = subject;
function refresh() {
for (const key of keys) {
last[key] = last[key] + (intended[key] - last[key]) / rigidity;
subject[key] = last[key];
}
requestAnimationFrame(refresh);
}
refresh();
return function update(values) {
intended = alias.has(values) ? alias.get(values) : values;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment