Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. <html>
  2. <head>
  3. <script>
  4. var pos = 0;
  5. //getting box element
  6. var box = document.getElementById("box");
  7. var time = setInterval(move, 10);
  8. document.getElementById("btn1").onclick = move(){
  9. if(pos >= 150){
  10. clearInterval(time);
  11. } else{
  12. pos += 1;
  13. box.style.left = pos+"px";
  14. }
  15. };
  16. </script>
  17. </head>
  18. <body>
  19. <h1><p id="p1" style="color:#dd3333">Sample Game</p></h1>
  20. <p id="p2" styel="color:#b5b5b5">Click on the button below</p>
  21. <style>
  22. #container{
  23. width:200px;
  24. height:200px;
  25. background:green;
  26. position:relative;
  27. }
  28. #box{
  29. width:50px;
  30. height:50px;
  31. background:red;
  32. position:absolute;
  33. }
  34. </style>
  35. <div id="container">
  36. <div id="box"></div>
  37. </div>
  38. <br></br>
  39. <button id="btn1">Click Me</button>
  40. </body>
  41.  
  42. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement