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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:14:43+00:00 2026-05-22T01:14:43+00:00

Please see the jsfiddle sample output: offset based on svg x:12 y:34 mouse click

  • 0

Please see the jsfiddle

sample output:
offset based on svg x:12 y:34
mouse click based on screen x:22 y:38
mouse coord based on svg x:10 y:4

The above sample output is generated when I click on the rectangle on the top-left corner.

As far as I understood, getScreenCTM interface provides the transformation matrix for the element (svg here). I got it as the first line. Second line indicate the mouse coordinate based on the screen coordinate. When I apply the transformation matrix to the mouse click, I expect the point will be translated to svg coordinate. That value is the 3 rd line above. I am not sure that it is correct. The rectangle has a y coordinate 10, and the click event is only availbake within the rectangle. So how could the mouse coord based on svg go below 10??


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE HTML><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head> 
</head>
<body>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />
<h1>sdsd</h1>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" baseProfile="full" height="200">
    <g fill="none" stroke="black" stroke-width="1" >
        <!-- Draw the axes of the original coordinate system -->
        <line x1="0" y1=".5" x2="400" y2=".5" />
        <line x1=".5" y1="0" x2=".5" y2="150" />
    </g>

    <g >
        <rect class="drag resize" x="10" y="10" width="100" height="50" fill="#c66" />
    </g>
</svg>

    <h2 id="op"></h2> 

          <script type="text/javascript" src="vb.js"></script>
</body>
</html>

var svg   = document.getElementsByTagName('svg')[0];
var svgNS = svg.getAttribute('xmlns');
var pt    = svg.createSVGPoint();
var el1 = document.getElementsByTagName('rect')[0];

var log_svgcursorPoint,
    log_mouseclick,
    log_mousecoord;


function svgcursorPoint(evt){
    pt.x = evt.clientX; pt.y = evt.clientY;
    var a = svg.getScreenCTM();
    log_svgcursorPoint = "offset based on svg"+ " x:" + a.e +" y:" + a.f;
    var b = a.inverse();
    return pt.matrixTransform(b);
};

    (function(el){
        el.addEventListener('mousedown',function(e){
            log_mouseclick = "mouse click based on screen"+ " x:" + e.clientX +" y:" + e.clientY ;
            var svgmouse   = svgcursorPoint(e);    
            log_mousecoord = "mouse coord based on svg"+ " x:" + svgmouse.x +" y:" +svgmouse.y;
            document.getElementById('op').innerHTML = log_svgcursorPoint + "<br>" + log_mouseclick + "<br>" + log_mousecoord;
        },false);
    })(el1);
  • 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-22T01:14:43+00:00Added an answer on May 22, 2026 at 1:14 am

    seems like a defect, depending on the browser zoom level. Raised an issue http://code.google.com/p/chromium/issues/detail?id=81995

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

Sidebar

Related Questions

Please see this: http://jsfiddle.net/uNbYu/1/ If you click submit, the button doesn't do anything, but
Please see this jsFiddle . Note that the click event works just fine (try
the .click() event doesn't seem to work on select, please see: http://jsfiddle.net/fMTzD/ Even before
Please see this jsFiddle: https://jsfiddle.net/Wmq6f/ I have a textarea that has a background image,
This question was asked here but the issue wasn't resolved. Please see this jsfiddle
please see this example http://jsfiddle.net/7trcV/ what I'm trying to achieve is ability to put
Please see my source code at: http://jsfiddle.net/rAmSG/9/ The blue item should be dropped at
This question is related to this question yesterday . Please see current jsfiddle here
please see my fiddle: http://jsfiddle.net/qVHg8/1/ Why isn't the fixedRightCol being positioned at right:0 of
Please check this one: http://jsfiddle.net/sasindu555/nNyxk/8/ You can see Description , Features and Contact Details

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.