Skip to content

Instantly share code, notes, and snippets.

@ykob
Last active January 21, 2016 02:54
Show Gist options
  • Save ykob/badd947faf9a2e136a69 to your computer and use it in GitHub Desktop.
Save ykob/badd947faf9a2e136a69 to your computer and use it in GitHub Desktop.
easing that used d3-ease.
import d3_ease from 'd3-ease';
export default class EasingObj {
constructor($elm, max, time) {
this.$elm = $elm;
this.max = max;
this.time_start = 0;
this.time_past = 0;
this.time_animate = time;
this.step = 0;
};
init() {
this.time_start = Date.now();
this.time_past = Date.now();
this.step = 0;
this.renderLoop();
};
updateCss(x) {
this.$elm.css({
transform: `translateX(${x}px)`,
});
};
render() {
this.time_past = Date.now();
this.step = (this.time_past - this.time_start) / this.time_animate;
if (this.step >= 1) this.step = 1;
this.updateCss(d3_ease.circleOut(this.step) * this.max);
};
renderLoop() {
this.render();
if (this.step < 1) {
requestAnimationFrame(()=> {
this.renderLoop();
});
}
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment