snipt

Ctrl+h for KB shortcuts

Text only

html 5 canvas example

1
2
3
4
5
6
7
var drawingCanvas = document.getElementById(‘myDrawing’);
// Check the element is in the DOM and the browser supports canvas
if(drawingCanvas.getContext) {
// Initaliase a 2-dimensional drawing context
var context = drawingCanvas.getContext(’2d’);
//Canvas commands go here
}
https://snipt.net/embed/cc26308c81fbf157d3a6c487882696ce/
/raw/cc26308c81fbf157d3a6c487882696ce/
cc26308c81fbf157d3a6c487882696ce
text
Text only
7
2019-08-15T02:07:05
True
False
False
/api/public/snipt/25982/
html-5-canvas-example
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>var drawingCanvas = document.getElementById(‘myDrawing’); </span><span id="L-2"><a name="L-2"></a>// Check the element is in the DOM and the browser supports canvas </span><span id="L-3"><a name="L-3"></a>if(drawingCanvas.getContext) { </span><span id="L-4"><a name="L-4"></a>// Initaliase a 2-dimensional drawing context </span><span id="L-5"><a name="L-5"></a>var context = drawingCanvas.getContext(’2d’); </span><span id="L-6"><a name="L-6"></a>//Canvas commands go here </span><span id="L-7"><a name="L-7"></a>} </span></pre></div> </td></tr></table>
5, canvas, example, html