Note that there are some explanatory texts on larger screens.

plurals
  1. PO-webkit-transform scale: how to get the coordinates of a visible area
    primarykey
    data
    text
    <p>I have an image which is displayed in a fixed div.</p> <pre><code>&lt;div&gt; &lt;img src="path/to/image" id="map" /&gt; &lt;/div&gt; </code></pre> <p>I'm using the -webkit-transform property to scale and navigate to the scaled image (not other browsers required. just webkit). All the stuff is being done with javascript/jquery. The navigation works in any directions. The maximum scale zoom is 10.</p> <p>E.g.:</p> <pre><code>&lt;button id="up"&gt;zoom in and move up&lt;/button&gt; $('#up').on('click',function() { $('#map').css({'webkitTransform':'translateX('+SOME_VALUE+'px) translateY('+SOME_VALUE+'px) scale('+ SCALE +')'}); }); </code></pre> <p>Everything works fine.</p> <p>The difficulty is in a different place: </p> <p>The image has a circle point on it. I know the coordinates of this point and its radius (e.g. X-100px,Y-100px,R-10px); These coordinates are related to the image.</p> <h2>Question:</h2> <p>How can I determine whether this circle point is visible or not if the image is scaled? How can I determine what area of the image is visible? How can I determine its <em>actual</em> coordinates in the resized state. Please do not hesitate to take a look at the example image that shows the desired:</p> <p><img src="https://i.stack.imgur.com/ukZgW.jpg" alt="Image"></p> <p>UPDATE:</p> <p>Unfortunately, the solutions given below are not quite correct. By multiplying jquery value of the height() and the scale rate you won't get the accurate results. I found the solution myself. There is the following javascript (not jquery) property:</p> <p><a href="https://developer.mozilla.org/en-US/docs/Web/API/element.getBoundingClientRect?redirectlocale=en-US&amp;redirectslug=DOM/element.getBoundingClientRect" rel="nofollow noreferrer">element.getBoundingClientRect</a></p> <p>This property reflects the real dimensions of the resized image and returns the real coordinates of an actual position. The usage with jquery is the following:</p> <pre><code>$('#some_element')[0].getBoundingClientRect(); </code></pre> <p>I hope it will be useful for those guys who meet the problem in the future:)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload