Advertisement
baseio

dskd-17-105 anna

Apr 28th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>clicker</title>
  5. <meta charset="utf-8">
  6.  
  7. <style>
  8.  
  9. body {
  10. font-family: helvetica;
  11. }
  12.  
  13. #blocks div {
  14. width:100px;
  15. height:100px;
  16. background-color: #F00;
  17. position: absolute;
  18. top: 30px;
  19. }
  20.  
  21. </style>
  22.  
  23. </head>
  24. <body>
  25.  
  26. <h3 id="score_label">Click the cubes to score!</h3>
  27.  
  28. <div id="blocks">
  29.  
  30. </div>
  31.  
  32. <script type="text/javascript">
  33.  
  34. var speed = 1;
  35. var score = 0;
  36. var missed = 0;
  37. var score_label = document.getElementById("score_label");
  38. var blocks_container = document.getElementById("blocks");
  39.  
  40.  
  41. function spawn(){
  42. var x = (document.documentElement.clientWidth -100) * Math.random();
  43. var y = - (100 + Math.random()*150);
  44. var b = document.createElement('div');
  45. b.style.left = x +"px";
  46. b.style.top = y +"px";
  47. blocks_container.appendChild(b);
  48.  
  49. b.onmousedown = function(evt){
  50. //console.log( evt.target );
  51. blocks_container.removeChild(evt.target);
  52. score ++;
  53. updateScoreLabel();
  54. };
  55. }
  56.  
  57. function update(){
  58. for (var i = 0; i < blocks_container.children.length; i++) {
  59. var block = blocks_container.children[i];
  60. //console.log('block', parseInt(block.style.top) );
  61. block.style.top = parseInt(block.style.top) + speed + 'px';
  62. }
  63.  
  64. requestAnimationFrame(update);
  65. }
  66.  
  67. function updateScoreLabel(){
  68. score_label.innerText = "Score: "+ score +", Missed: "+ missed;
  69. }
  70.  
  71.  
  72. setInterval( spawn, 1000 );
  73. update();
  74.  
  75.  
  76. </script>
  77.  
  78.  
  79. </body>
  80. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement