HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
Canvas Object : Draw a rectangle, scale to 200%, then draw rectangle again
The numbers in the table specify the first browser version that fully supports the method.
Method | |||||
---|---|---|---|---|---|
scale() | 4.0 | 9.0 | 3.6 | 4.0 | 10.1 |
The scale() method scales the current drawing, bigger or smaller.
JavaScript syntax: | context.scale(scalewidth, scaleheight); |
---|
Parameter | Description | Play it |
---|---|---|
scalewidth | Scales the width of the current drawing (1=100%, 0.5=50%, 2=200%, etc.) | Play it » |
scaleheight | Scales the height of the current drawing (1=100%, 0.5=50%, 2=200%, etc.) | Play it » |
Draw a rectangle, scale to 200%, draw rectangle again, scale to 200%, draw rectangle again, scale to 200%, draw rectangle again:
JavaScript:
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.strokeRect(5, 5, 25, 15);
ctx.scale(2, 2);
ctx.strokeRect(5, 5, 25, 15);
ctx.scale(2, 2);
ctx.strokeRect(5, 5, 25, 15);
ctx.scale(2, 2);
ctx.strokeRect(5, 5, 25, 15);
❮ Canvas Object