In my latest program update, I am facing an issue with the maxTop variable in my box div. It seems to be returning a NaN value, and I'm struggling to figure out why.
The problem I'm encountering is that when the ball moves, it bounces off the left and right walls but does not react correctly when it reaches the top or bottom. Any insights into why this might be happening?
Here are the variables I'm working with:
currentLeftPos = parseInt($("#ball").css('left'));
currentTopPos = parseInt($("#ball").css('top'));
var newLeftPos = currentLeftPos + velocity_x;
var newTopPos = currentTopPos + velocity_y;
if( newLeftPos >= maxLeft || newLeftPos <= 0)
velocity_x *= -1;
if( newTopPos >= maxTop || newTopPos <= 0)
velocity_y *= -1;
maxLeft = parseInt($("#outerbox").css('width')) -parseInt($("#outerbox").css('border-left-width')) - parseInt($("#ball").css('width'));
maxTop = parseInt($("#outerbox").css('top')) -parseInt($("#outerbox").css('border-left-top')) - parseInt($("#ball").css('top'));