let ball = document.body.appendChild(document.createElement('div'));
Object.assign(ball.style, {
position: 'absolute',
background: 'red',
width: '100px', height: '100px',
borderRadius: '50%'
});
let x = -100;
let y = window.innerHeight / 5;
let vx = 3;
let vy = -3;
let grav = .3;
var decay = 0.5;
function loop() {
let floor = window.innerHeight - 100;
x += vx;
y += vy;
vy += grav;
if (y > floor) {
vy *= -decay;
vx *= decay;
y = floor;
}
ball.style.transform = `translate(${x}px, ${y}px)`;
window.requestAnimationFrame(loop);
}
loop();
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.