Blogger Information
Blog 16
fans 0
comment 0
visits 9640
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
飞舞的气泡
坨坨
Original
629 people have browsed it


<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>

  1. #main {
  2. width:800px;
  3. height:600px;
  4. background: #ccc;
  5. position: relative;
  6. }
  7. ball{
  8. }
  9. </style>
  10. </head>
  11. <body>
  12. <input type="button" value="弹出球" id="btn">
  13. <div id="main">
  14. </div>
  15. <script>
  16. var main = document.getElementById('main');
  17. var btn = document.getElementById('btn');
  18. btn.onclick = function () {
  19. var color = "#"+parseInt(Math.random()*1000);
  20. var wh = Math.floor(Math.random()*50)+20;
  21. var ball = document.createElement('div')
  22. ball.style.cssText = 'position: absolute;border-radius: 50%;'
  23. ball.style.background = color;
  24. ball.style.width = wh+'px';
  25. ball.style.height = wh+'px';
  26. var top = main.clientHeight/2 - wh;
  27. var left = main.clientWidth/2 - wh;
  28. ball.style.top = top+'px';
  29. ball.style.left = left+'px';
  30. main.appendChild(ball)
  31. var x = Math.floor(Math.random()*20)+1
  32. var y = Math.floor(Math.random()*20)+1
  33. setInterval(function () {
  34. left+=x;
  35. top+=y;
  36. if (left<=main.offsetLeft || left > (main.offsetLeft+main.offsetWidth-ball.offsetWidth) ){
  37. x = -x;
  38. }
  39. if (top<=main.offsetTop || top > (main.offsetTop+main.offsetHeight-ball.offsetHeight-3)){
  40. y= -y;
  41. }
  42. ball.style.left = left
  43. ball.style.top = top
  44. },100)
  45. }
  46. </script>
  47. </body>
  48. </html>
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post