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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:48:10+00:00 2026-05-26T13:48:10+00:00

I have to do group translation (SVG) for specific reason. I don’t know why

  • 0

I have to do group translation (SVG) for specific reason. I don’t know why I can’t make it properly, because after translation is made, on the other click on group it resets translation on start position and make fool of me running around over SVG canvas.
I write the barebone example at link: http://www.atarado.com/en/stripboard-layout-software/group-translation-problem.svg , and here’s the code:

<svg xmlns="http://www.w3.org/2000/svg"
 xmlns:xlink="http://www.w3.org/1999/xlink">
<script><![CDATA[
function startMove(evt){
 x1=evt.clientX;
 y1=evt.clientY;
 group=evt.target.parentNode;
 group.setAttribute("onmousemove","moveIt(evt)");
}
function moveIt(evt){
 dx=evt.clientX-x1;
 dy=evt.clientY-y1;
 group.setAttributeNS(null,"transform","translate("+ dx + ", " + dy +")");
}
function drop(){
 group.setAttributeNS(null, "onmousemove",null);
}
]]></script>
<rect x="0" y="0" width="100%" height="100%" fill="dodgerblue"/>

<g id="BC" transform="translate(0, 0)" onmousedown="startMove(evt)" onmouseup="drop()"><circle id="C" cx="60" cy="60" r="22" fill="lightgrey" stroke="black" stroke-width="8"/><circle id="B" cx="120" cy="60" r="22" fill="orange" stroke="black" stroke-width="8" /></g>
</svg>

Anybody willing to help is welcome.

  • 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-26T13:48:11+00:00Added an answer on May 26, 2026 at 1:48 pm

    The reason position of the group resets on the second move is that you set the transform to translation with (dx, dy) being equal to the difference between the position the move started (x1, y1) and the current position (evt.clientX, evt.clientY). This means that when you click the second time and them move the mouse slightly then dx and dy are small numbers. They are then used to set the transform to something slightly off the initial position. Remember that at any time the transform applied to the group must describe the transformation from the initial position of the group.

    One way to fix the problem would be to store the total delta from all the moves applied to the group so far and use this accumulated (dx, dy) to build the transform. For example:

    <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    <script><![CDATA[
    function startMove(evt){
      group=evt.target.parentNode;
      x1=evt.clientX - group.$x;
      y1=evt.clientY - group.$y;
      group.setAttribute("onmousemove","moveIt(evt)");
    }
    function moveIt(evt){
      dx=evt.clientX-x1;
      dy=evt.clientY-y1;
      group.setAttributeNS(null,"transform","translate("+ dx + ", " + dy +")");
      group.$x = dx; 
      group.$y = dy; 
    }
    function drop(){
      group.setAttributeNS(null, "onmousemove",null);
    }
    ]]></script>
    <rect x="0" y="0" width="100%" height="100%" fill="dodgerblue"/>
    <g id="BC" transform="translate(0, 0)" onmousedown="startMove(evt)" onmouseup="drop()">
      <circle id="C" cx="60" cy="60" r="22" fill="lightgrey" stroke="black" stroke-width="8"/>
      <circle id="B" cx="120" cy="60" r="22" fill="orange" stroke="black" stroke-width="8" />
    </g>
    <script><![CDATA[
    var group=document.getElementById("BC");
    group.$x = 0;
    group.$y = 0;
    ]]></script>
    </svg>
    

    We have added two properties to the group elememt: $x and $y to store the current position of the element (or the accumulated deltas from all the moves so far, depending on the way you look at it). They’re initialized to zero in the script located after the element with ID “BC” is defined. They are updated in moveIt() and consumed in startMove(). Since we subtract our new deltas ($x, $y) from (x1, y1) in startMove(), these new deltas effectively get added to (dx, dy) later in moveIt(). This ensures (dx, dy) accounts for all the moves so far as well as for the current move.

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

Sidebar

Related Questions

I have a group of borders that make up a small map. Ideally I'd
I have group of stored procedures with names like 'somename_%'. Are there any way
I have a group of checkboxes that I only want to allow a set
I have a group of strings in Javascript and I need to write a
We have a group of a few developers and some business analysts. We as
I have a group of three radio buttons. Depending on which radio button is
I have one group of 3 asp.net textboxes and one group of 2 asp.net
I have a group of buttons that should act like toggle buttons, but also
I have a group of radio buttons in my Swing application that have a
I have a group of 13 properties in a class. I created a struct

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.