In my experience, the only sure-fire way to get stuff like this to work is using JQuery (don't be afraid, it's just an external script file you have to include). Then you can use a statement like
$('#element').position()
or
$('#element').offset()
to get the current coordinates, which works excellently across any and all browsers I've encountered so far.
Answer from Udo on Stack OverflowIn my experience, the only sure-fire way to get stuff like this to work is using JQuery (don't be afraid, it's just an external script file you have to include). Then you can use a statement like
$('#element').position()
or
$('#element').offset()
to get the current coordinates, which works excellently across any and all browsers I've encountered so far.
I found this Solution from the web... This Totally Solved my Problem. Please check this link for the origin. http://www.quirksmode.org/js/findpos.html
/** This script finds the real position,
* so if you resize the page and run the script again,
* it points to the correct new position of the element.
*/
function findPos(obj){
var curleft = 0;
var curtop = 0;
if (obj.offsetParent) {
do {
curleft += obj.offsetLeft;
curtop += obj.offsetTop;
} while (obj = obj.offsetParent);
return {X:curleft,Y:curtop};
}
}
Works Perfectly in Firefox, IE8, Opera (Hope in others too) Thanks to those who share their knowledge... Regards,
ADynaMic
php - Get coordinates of a particular section of the image - Stack Overflow
Trying to gather coordinates of images on html webpages
How to find coordinates - HTML-CSS - The freeCodeCamp Forum
How can I find the coordinates of an image within another image?
I'm working on something similar, but I wanted to make it responsive - not if you zoom in, image will be bigger and areas too. I didn't use <map>, because the coords are absolute. I used this:
<div id="mapdiv">
<img src="link" id="imgmap" alt="" />
<a href="target"><div id="box1">Here is the text</div></a>
<div id="box2" onclick="alert('You can use js too')"></div>
</div>
And CSS:
#imgmap {
width: 100%;
}
div#mapdiv {
position: relative; /* thanks to this... */
}
div#menu div {
position: absolute; /* ...and this are boxes positioned relatively inside the imgdiv */
border: 1px dashed blue; /* for finding coords, remove after you are done */
}
div#box1 {
left: 21%; /* my coords, make your own by trying and trying... */
top: 26.5%;
height: 5%;
width: 6.5%
}
div#box2 {
left: 7.5%;
top: 66.2%;
height: 24.5%;
width: 31.5%;
}
if you want to add text, then you better use real links and set them on top of your areas wich are quiet good rectangle.
example:
.map {
position: relative;
}
.map img {
display: block;
width: 100%;
}
.map a {
position: absolute;
top: 48.6%;
left: 9.118%;
width: 19.8%;
height: 19%;
transform: rotate(-1.375deg);
border-radius: 50% 50% 0px 0 / 0.25vw;
transition: 0.5s;
color:#3F4754;
display:flex;
align-items:center;
justify-content:center;
font-size:4vw;
font-weight:bold;
font-family:courier;
font-variant:small-caps;
text-decoration:none;
text-shadow:-2px -2px 2px black
}
.map a + a {
top: 48%;
left: 70%;
transform: rotate(3deg);
transform-origin: bottom right
}
a:hover {
color: white;
background:linear-gradient(to bottom left, rgba(0, 0, 0, 0.5), transparent);
text-shadow:2px 2px 2px black
}
<div class="map">
<img src="https://i.sstatic.net/mDEuy.jpg" />
<a href="#1">hover me</a>
<a href="#2">or me</a>
</div>
use your own style and ids or class
Hi all, I'm new to python and as stated in the title - I'm looking to learn how to find the coordinates of an image on a webpage. the image is actually a puzzle but the location is in the center. What I've been doing is pixel coordinates however, this isn't great however, because I want to use it on different computers and the pixel coordinates won't due for the different screen resolutions