Search code examples
jquerykeydownpong

jQuery: restrict keydown movement of object


I am trying to work on a ping pong kind of game in jQuery and I was wondering how can I restrict the slider position inside a container.

I also need help with how to generate the ball/box and how to make it bounce on the side and top wall of the container.

I have managed to work on it but I am still struggling to retain the slider inside the container and struggling on the bouncing the ball around.

Any help would be highly appreciated. MyCodeSoFar


Solution

  • I'm sorry but your code is a bit messy for me. Whatever, I found this idea of a js pong like game funny and I adapted your code to do what you intended.

    Just have a look at this fiddle and feel free to send me some feedback.