class smoothMove {
constructor(target, speed = 2, wrapWidth = window.innerWidth, wrapHeight = window.innerHeight) {
this.target = target;
this.angle = 0;
this.speed = speed;
this.center = {
x: wrapWidth / 2 - this.target.width() / 2,
y: wrapHeight / 2 - this.target.height() / 2
};
this.radius = window.innerHeight / 2;
return this;
}
getRadian(angle) {
return angle * Math.PI / 180;
}
play() {
let radian = this.getRadian(this.angle);
let offsetX = Math.sin(radian) * this.radius;
let offsetZ = Math.cos(radian) * this.radius;
TweenMax.set(this.target, {
x: this.center.x + offsetX,
y: this.center.y,
z: offsetZ * 1.5,
});
this.angle += this.speed;
requestAnimationFrame(() => {
this.play();
});
}
}
let anim = new smoothMove($('.target'));
anim.play();