简体   繁体   中英

How to get a shape's X and Y axis coordinate location from a image by php or javascript?

Its an image and I need to know the X and Y axis coordinate location (in px or anything) of the shape. For example-> The distance between the shape and the top of page or image is 20 px and left 15px. Is it possible by php or javascript?

图片在这里

Ok, so i assume you want to do this:

(given an image)

HTML:

<img id="img" src="image.png">

now, to get the x and y pos:

javascript:

function getCoordsOfElement(query) {
    var el = document.querySelector(query);
    var offset = el.getBoundingClientRect();

    return {
        x: offset.left,
        y: offset.top
    };
}

// get the x and y offset of the image
var offset = getCoordsOfElement('#img');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM