开发者

Mysterious bug that I can't seem to identify

开发者 https://www.devze.com 2023-03-23 16:04 出处:网络
I am just trying to practice javascript and Jquery, so I\'m working on this little script that is a rudimentary simulation of a ball bouncing of the sides of the document. This should be very trivial

I am just trying to practice javascript and Jquery, so I'm working on this little script that is a rudimentary simulation of a ball bouncing of the sides of the document. This should be very trivial I feel, but I am running into a lot of unexpected behavior. This I suspect is due to a lack of understanding of DOM and such.

Rather than trying to explain in detail the problematic behavior, I'll provide you this jsfiddle of the script.

http://jsfiddle.net/VqqwN/1/

As you can see, when the object reaches the top of the page, it simply continues going, telling me that the cond开发者_开发技巧itional dealing with the Y coordinate is evaluating false, when it should be true.

Thanks for all the help!


The issue is that you are animating the position over 10ms... but your loop is executing faster than that, so the position isn't changing fast enough for the comparison in the loop to be valid.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号