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 7062507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:36:08+00:00 2026-05-28T04:36:08+00:00

I would like to transform an element on a SVG canvas by a transformation

  • 0

I would like to transform an element on a SVG canvas by a transformation matrix (that is decided on the fly). I can do it with JQuery-SVG animate() but it doesn’t result smooth at all. So I thought to use the native SVG animateTransform, and the question is:

  • how can I make it start when I want (maybe beginElement()), and
  • how can I set the parameters from the matrix on the fly?

thanks in advance 😀

  • 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-05-28T04:36:09+00:00Added an answer on May 28, 2026 at 4:36 am

    Thanks for your answer!
    Since i wanted to use native SVG animations I found this solution (still not working perfectly). This is a sort of version of the unexisting animateTransform(attributeName=”transform” type=”matrix”)

    NOTE: i keep the svg transformation for each element in group.transform, and group.transform.matrix() returns just the transformation matrix of that element.

    I first add these elements to the element i want to animate:

    <animateTransform id="canvTranslate" begin="indefinite" attributeName="transform" type="translate" to="" dur="1s" additive="sum" fill="freeze"/>
    <animateTransform id="canvRotate" begin="indefinite" attributeName="transform" type="rotate" to="" dur="1s" additive="sum" fill="freeze"/>
    <animateTransform id="canvScale" begin="indefinite" attributeName="transform" type="scale" to="" dur="1s" additive="sum" fill="freeze"/>
    

    Then i do:

     var tMatrix = transformation.matrix(); //this is the transformation i want to obtain
        var cMatrix = group.transform.matrix(); //this is the actual CTM of the element
    
        //getting the animations
        var animTrans = document.getElementById('canvTranslate');
        var animRotaz = document.getElementById('canvRotate');
        var animScale = document.getElementById('canvScale');
    
        //setting duration (it's got somewhere before)
        animTrans.setAttribute('dur', duration/1000+'s');
        animRotaz.setAttribute('dur', duration/1000+'s');
        animScale.setAttribute('dur', duration/1000+'s');
    
        //calculating the 'from' attribute
        var transX = cMatrix.e;
        var transY = cMatrix.f;
        var scaleX = Math.sqrt(Math.pow(cMatrix.a, 2)+Math.pow(cMatrix.b, 2));
            var rotate = Math.atan(cMatrix.c/cMatrix.d);
    
        animTrans.setAttribute('from', transX+','+transY);
        animRotaz.setAttribute('from', -rotate*180/Math.PI);
        animScale.setAttribute('from', scaleX);
        //end 'from'
    
        //calculating the 'to' attribute to set
        var transX = tMatrix.e;
        var transY = tMatrix.f;
        var scaleX = Math.sqrt(Math.pow(tMatrix.a, 2)+Math.pow(tMatrix.b, 2));
        var rotate = Math.atan(tMatrix.c/tMatrix.d);
    
        animTrans.setAttribute('to', transX+','+transY);
        animRotaz.setAttribute('to', -rotate*180/Math.PI);
        animScale.setAttribute('to', scaleX);
        //end 'to'
    
        animTrans.beginElement();
        animRotaz.beginElement();
        animScale.beginElement();
    

    group.transform = transformation; and finally, to update the transform attribute of the element:

        setTimeout(function(){ //i will change this somehow better :)
    
            //this is a problematic step. with it animations work on Chrome, without it they work good on firefox and opera too
            $(group).attr('transform', 'matrix('+tMatrix.a+','+tMatrix.b+','+tMatrix.c+','+tMatrix.d+','+tMatrix.e+','+tMatrix.f+')');
        }, duration+100);
    

    This final step is the problematic one. I can’t understand why with it works fine in Chrome, while the animation ends up much more scaled in Firefox and Opera (where not calling setTimeout works just fine).

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

Sidebar

Related Questions

I parsed a transform attribute from an element in an SVG file something like
Would like to make anapplication in Java that will not automatically parse parameters used
I would like to extract the individual elements of a composite webkit transformation in
I would like to remove all elements from XML except content of element called
I am performing a CSS transform: rotate on a parent, yet would like to
I would like to add a default value for an asp textbox that looks
i would like convert xml, that: tag is the name of current node (this,
I would like to transform an XML document using xslt with a set of
I have a <select> element within which I would like to Capitalize the text
I have several XDocuments that look like: <Test> <element location=.\jnk.txt status=(modified)/> <element location=.\jnk.xml status=(overload)/>

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.