Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to save users last mouse position on a html5 canvas?
    primarykey
    data
    text
    <p>I followed the tutorial from phpacademy on youtube on how to make a HTML5 drawing app.</p> <p>I'm now done with this tutorial and is trying to make it have more features. I'm trying to add a text tool at this moment, I know how to draw text onto the canvas and how to change font and textcolor.</p> <p>What I need help with, is on how to save the users last clicked mouse position on the canvas using javascript.</p> <p>HTML:</p> <pre><code>&lt;!doctype html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Html5 Drawing App!&lt;/title&gt; &lt;link rel="stylesheet" type="text/css" href="style.css"&gt; &lt;/head&gt; &lt;body style='margin: 0'&gt; &lt;div id="toolbar"&gt; &lt;div id="rad"&gt; Radius &lt;span id="radval"&gt;10&lt;/span&gt; &lt;div id="decRad" class="radcontrol"&gt;-&lt;/div&gt; &lt;div id="incRad" class="radcontrol"&gt;+&lt;/div&gt; &lt;/div&gt; &lt;div id="colors"&gt; &lt;/div&gt; &lt;div id="save"&gt; &lt;iframe id="downloadframe" hidden=yes&gt;&lt;/iframe&gt; Save &lt;/div&gt; &lt;div id="clear"&gt; Clear &lt;/div&gt; &lt;div id="text"&gt; Text &lt;/div&gt; &lt;/div&gt; &lt;canvas id="canvas" style="display: block;"&gt; Sorry, Your Browser Is Unsupported. Switch To Another Browser &lt;/canvas&gt; &lt;script src="main.js"&gt;&lt;/script&gt; &lt;script src="radius.js"&gt;&lt;/script&gt; &lt;script src="colors.js"&gt;&lt;/script&gt; &lt;script src="save.js"&gt;&lt;/script&gt; &lt;script src="text.js"&gt;&lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Current JS:</p> <pre><code>var pos = new array(0,0); var canvas = document.getElementById("canvas"); var textButton = document.getElementById('text'); var context = canvas.getContext('2d'); context.font = "bold 16px Arial"; </code></pre> <p>If you need any more details, just tell me.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload