HTML5 Canvas Translate () method

Source: Internet
Author: User

Instance

Draws a rectangle at position (10,10) and sets the new (0,0) position to (70,70). Draw the new rectangle again (note that the rectangle is now drawn from the position (80,80)):

Your Browser does not support the HTML5 canvas tag.

Javascript:

var C=document.getelementbyid ("MyCanvas"), Var ctx=c.getcontext ("2d"), Ctx.fillrect (10,10,100,50) ctx.translate(70,70); ; Ctx.fillrect (10,10,100,50);

Browser support

Internet Explorer 9, Firefox, Opera, Chrome, and Safari support the translate () method.

Note: Internet Explorer 8 or earlier browsers do not support the <canvas> element.

Definition and usage

The translate () method remap the (0,0) position on the canvas.

Note: When you call a method such as FillRect () after translate (), the value is added to the x and Y coordinate values.

JavaScript Syntax:
Context.translate (x,y);
Parameter values
Parameters Description
X Value added to the horizontal coordinate (x)
Y Value added to the vertical coordinate (y)

HTML5 Canvas Translate () method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.