I have a requirement where on clicking on a human body image I have to display a circle on that body part. I’m able to render the circle but not on the body part. And if I scroll and click on the same body part the circle renders in a different place. Here’s the example.
This also creates an issue with different screen sizes.
2
Answers
I made some dits to your code, you can cehck if this works for you.
Code Sandbox
event.target.getBoundingClientRect()
returns the size of an element and its position relative to the viewport. Andevent.target.naturalWidth
andevent.target.naturalHeight
provides the natural width and height of<img/>
(original pixels wide)so you can calculate absolute position of circle which will be placed on image by
event.target.natural(width or height) / rect.(width or height)
Example