Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8225173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:19:36+00:00 2026-06-07T15:19:36+00:00

In HTML5 I want to implement transform functionality to canvas element, so user can

  • 0

In HTML5 I want to implement transform functionality to canvas element, so user can translate (move), scale (zoom in/out) and rotate the canvas element. Each such tranformation can be done with different transform-origin point.

First tranformation is easy:

function transform(el, value, origin) {
  el.style.Transform = value;
  el.style.MozTransform = value;
  el.style.msTransform = value;
  el.style.OTransform = value;
  el.style.webkitTransform = value;
  el.style.TransformOrigin = origin;
  el.style.MozTransformOrigin = origin;
  el.style.msTransformOrigin = origin;
  el.style.OTransformOrigin = origin;
  el.style.webkitTransformOrigin = origin;
}

transform(myCanvas, 'translate('+ dx +'px, ' + dy + 'px) ' +
                    'scale(' + zoom + ', ' + zoom + ') ' +
                    'rotate(' + angle + 'deg)',
                    cx + 'px ' + cy + 'px');

User will move or zoom or rotate the element, not everything at once, so some parameters of tranformation will stay default (dx = 0, dy = 0, zoom = 1, angle = 0).

After such tranformation, if user wants to make another transformation (and antother, and another…), how can I combine (dx1, dy1, zoom1, angle1, cx1, cy1) with (dx2, dy2, zoom2, angle2, cx2, cy2) to get final values that can be combine later with new tranformation parameters? I cannot append another tranformation to transform parameter, because tranform-origin may be different. Is there a formula how to combine tranformations with different transform-origin points?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T15:19:39+00:00Added an answer on June 7, 2026 at 3:19 pm

    You don’t have to learn matrix math. According to the CSS Transform specification

    1. Start with the identity matrix.
    2. Translate by the computed X, Y and Z values of ‘transform-origin’.
    3. Multiply by each of the transform functions in ‘transform’ property in turn
    4. Translate by the negated computed X, Y and Z values of ‘transform-origin’

    In other words, transform-origin: A; transform: B is the same as transform: translate(-A) B translate(A). (Transformations apply from right to left, so the first thing you want to happen goes at the end.)

    So use the above rules to eliminate transform-origin and now you just have plain transforms you can concatenate.

    Example:

    1. transform-origin: 5px 5px; transform: translate(10px, 40px)
    2. transform-origin: 25px 30px; transform: scale(2)
    3. transform-origin: 10px 10px; transform: rotate(30deg)

    becomes

    1. transform: translate(-5px, -5px) translate(10px, 40px) translate(5px, 5px)
    2. transform: translate(-25px, -30px) scale(2) translate(25px, 30px)
    3. transform: translate(-10px, -10px) rotate(30deg) translate(10px, 10px)

    Now you can combine them since they all agree on the origin (i.e., no origin)

    transform: translate(-5px, -5px) translate(10px, 40px) translate(5px, 5px) translate(-25px, -30px) scale(2) translate(25px, 30px) translate(-10px, -10px) rotate(30deg) translate(10px, 10px)

    Of course you can collapse the consecutive translations if you want

    transform: translate(-15px, 10px) scale(2) translate(15px, 20px) rotate(30deg) translate(10px, 10px)

    Or you can dig out your math textbook and compute the final transformation matrix.

    Edit: Transforms apply right to left.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to implement vertical scrolling of the contents of a HTML5 canvas element.
My project is a canvas (not HTML5 element) where a user can add images,
I want to create an application that can transform text the user enters in
I want to create a dynamic HTML5 canvas animation. This animation should use server
I want to implement a web text editor able to recognize when the user
I want to understand how to implement HTML5 <audio> fallback using Javascript... i.e. I
I want to implement a guider, a dialog box that guides a user through
I am trying to implement a html5 drawing app. Currently, I can allow for
I am new with HTML5. I have to implement such a functionality that I
I want to use image maps & http://dev.w3.org/html5/spec/the-map-element.html#dom-map-images . I haven't seen much of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.