Changed around line 1
+ const ball = document.getElementById('ball');
+ let isHeld = false;
+ let startY = 0;
+ let currentY = 0;
+ let velocity = 0;
+ const gravity = 0.5;
+ const bounceFactor = -0.7;
+
+ ball.addEventListener('mousedown', (e) => {
+ isHeld = true;
+ startY = e.clientY - currentY;
+ ball.style.transition = 'none';
+ });
+
+ window.addEventListener('mousemove', (e) => {
+ if (isHeld) {
+ currentY = e.clientY - startY;
+ ball.style.transform = `translateY(${currentY}px)`;
+ }
+ });
+
+ window.addEventListener('mouseup', () => {
+ if (isHeld) {
+ isHeld = false;
+ velocity = 0;
+ ball.style.transition = 'transform 0.1s ease-out';
+ animateBall();
+ }
+ });
+
+ function animateBall() {
+ if (!isHeld) {
+ velocity += gravity;
+ currentY += velocity;
+
+ if (currentY > 0) {
+ currentY = 0;
+ velocity *= bounceFactor;
+ }
+
+ ball.style.transform = `translateY(${currentY}px)`;
+
+ if (Math.abs(velocity) > 0.1) {
+ requestAnimationFrame(animateBall);
+ }
+ }
+ }