Advertisement
Naitenne

HTML canvas outside/inside div

Dec 9th, 2017
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.50 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  5.         <style>
  6. canvas {
  7.     border: 1px solid #d3d3d3;
  8.     background-color: #f1f1f1;
  9.     position: absolute;
  10.     top: 0px; left: 0px;
  11.     z-index: 10;
  12. }
  13. .button {
  14.     background-color: #FAFAFA;
  15.     border: 1px solid black;
  16.     width:200px;
  17.     color: black;
  18.     padding: 15px 32px;
  19.     text-align: center;
  20.     text-decoration: none;
  21.     display: inline-block;
  22.     font-size: 16px;
  23.     margin: 4px 2px;
  24.     cursor: pointer;
  25.     transition-duration: 0.4s;
  26. }
  27. .button:focus {
  28.   outline: none;
  29. }
  30. .button:active {
  31.     background-color: #e7e7e7;
  32. }
  33.         </style>
  34.     </head>
  35.     <body>
  36.         <div style = "width:1200px; height:600px; border:1px solid #000; text-align: center; vertical-align:middle; display: table-cell;">
  37.             <ul style = "list-style-type: none;">
  38.                 <li><button class = "button" onclick = "startGame()">Start</button></li>
  39.                 <li><button class = "button">Records</button></li>
  40.             </ul>
  41.         </div>
  42.         <p id="footer"></p>
  43.  
  44.         <script>
  45.  
  46. function startGame() {
  47.     myGameArea.start();
  48. }
  49.  
  50. var myGameArea = {
  51.     canvas : document.createElement("canvas"),
  52.     start : function() {
  53.         this.canvas.width = 600;
  54.         this.canvas.height = 450;
  55.         this.context = this.canvas.getContext("2d");
  56.         document.body.insertBefore(this.canvas, document.getElementById("footer"));
  57.         ctx = myGameArea.context;
  58.         ctx.fillStyle = "red";
  59.         ctx.fillRect(0, 0, 50, 50);
  60.     }
  61. }
  62.  
  63.         </script>
  64.     </body>
  65. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement