Lokasi:homepage > Kod kesan khas JS > Latar belakang dan susun atur

Kod JS perlanggaran bola gelembung

2020-06-25 105jumlah tontonan
Ten small balls appear at the same time and can be modified as needed. If you want the ball to appear randomly, you just need to annotate 58 lines of code and 57 lines of comments. This writing method is still very clear. After the test, the effect is still very good. You may think that the code is quite long, but the idea is quite clear: first, create the screen class, and give the ball movement and collision required by various attribute variables in the screen constructor, such as ballnum, spring, bounce, gravity, and so on Then use prototype prototype prototype to give corresponding functions, such as create ball, balls, hit balls, ball moving, add corresponding functions to each function, and finally click event with button to call function, that's all. I just annotate the effect of the click here, and the page will change randomly if I refresh it directly.