4
How can I use the tag canvas
HTML5 and make this change in real time as I input the data into input
? I’ve already done the form
and put the tag canvas
page. I was wondering if JQuery
it is possible to change the data entered in input
and at the same time change the measure of canvas
:
Code:
<input type="text"name="largura"/>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var largura = document.getElementById("largura").focus().value;
var altura = document.getElementById("altura")..focus().value;
ctx.fillStyle = "#FF0000";
ctx.fillRect(5,5,largura,altura);
</script>
How would the function in the JQuery
that would change these variables in real time?
Type what would you like to change? Sizes? Color? Position?
– Fernando Leal
Opa Fernando, watch the attention! I wanted to change the size for now. I actually want to change the whole canvas structure, but to start I wanted to know how to change the width and height of the rectangle. But it would have to occur as the value is entered in the input.
– Jaciel Placidino
Just a comment, this is wrong
document.getElementById("altura")..focus().value;
the broker isdocument.getElementById("altura").focus().value;
– Guilherme Nascimento