Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <script>
- var pos = 0;
- //getting box element
- var box = document.getElementById("box");
- var time = setInterval(move, 10);
- document.getElementById("btn1").onclick = move(){
- if(pos >= 150){
- clearInterval(time);
- } else{
- pos += 1;
- box.style.left = pos+"px";
- }
- };
- </script>
- </head>
- <body>
- <h1><p id="p1" style="color:#dd3333">Sample Game</p></h1>
- <p id="p2" styel="color:#b5b5b5">Click on the button below</p>
- <style>
- #container{
- width:200px;
- height:200px;
- background:green;
- position:relative;
- }
- #box{
- width:50px;
- height:50px;
- background:red;
- position:absolute;
- }
- </style>
- <div id="container">
- <div id="box"></div>
- </div>
- <br></br>
- <button id="btn1">Click Me</button>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement