HTML                
            Brezentowy
        
        
            
    Szukaj…
Parametry
| Atrybut | Opis | 
|---|---|
| wysokość | Określa wysokość płótna | 
| szerokość | Określa szerokość płótna | 
Uwagi
- Ten tag nie jest kompatybilny z wersjami Internet Explorera mniejszymi niż 9. Sprawdź caniuse.com pod kątem kompatybilności przeglądarki.
 -  
canvasjest tylko pojemnikiem na grafikę, a faktyczne rysowanie grafiki odbywa się za pomocą JavaScript. 
Podstawowy przykład
 Element canvas został wprowadzony w HTML5 do rysowania grafiki. 
<canvas id="myCanvas">
   Cannot display graphic. Canvas is not supported by your browser (IE<9)
</canvas>
  Powyższe spowoduje utworzenie przezroczystego elementu HTML <canvas> o rozmiarze 300 × 150 pikseli. 
 Za pomocą elementu canvas można rysować niesamowite rzeczy, takie jak kształty, wykresy, manipulować obrazami, tworzyć wciągające gry itp. Za pomocą JavaScript . 
 W canvas „s 2D rozciągliwej warstwy powierzchniowej przedmiot jest zwany dalej jako CanvasRenderingContext2D ; lub z HTMLCanvasElement przy użyciu metody .getContext("2d") : 
var ctx = document.getElementById("myCanvas").getContext("2d");
// now we can refer to the canvas's 2D layer context using `ctx`
ctx.fillStyle = "#f00";
ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height); // x, y, width, height
ctx.fillStyle = "#000";
ctx.fillText("My red canvas with some black text", 24, 32); // text, x, y
         Rysowanie dwóch prostokątów na a
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>Draw two rectangles on the canvas</title>
    <style>
      canvas{
          border:1px solid gray;
      }
    </style>
    <script async>
      window.onload = init; // call init() once the window is completely loaded
      function init(){
        // #1 - get reference to <canvas> element
        var canvas = document.querySelector('canvas');
        
        // #2 - get reference to the drawing context and drawing API
        var ctx = canvas.getContext('2d');
        // #3 - all fill operations are now in red
        ctx.fillStyle = 'red'; 
        // #4 - fill a 100x100 rectangle at x=0,y=0
        ctx.fillRect(0,0,100,100);
        
        // #5 - all fill operations are now in green
        ctx.fillStyle = 'green'; 
        
        // #6 - fill a 50x50 rectangle at x=25,y=25
        ctx.fillRect(25,25,50,50);
        
      }
      </script>
</head>
<body>
  <canvas width=300 height=200>Your browser does not support canvas.</canvas>
</body>
</html>
 Ten przykład wygląda następująco:
Modified text is an extract of the original Stack Overflow Documentation
        Licencjonowany na podstawie CC BY-SA 3.0
        Nie związany z Stack Overflow
    