I'm working on a program that shows the photoshop window and when you click on the image, it will also gets the click pixels exactly where you clicked on the image and i'm doing this by giving relative positions:
$('#screen').on('click', function(e) {
var offset = $(this).offset();
const relativeX = e.pageX - offset.left
const relativeY = e.pageY - offset.top
console.log('X: '+relativeX+'\nY: '+relativeY)
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<img id="screen" src="https://i.ibb.co/9brxVbK/image-2020-12-16-081145.png">
This works fine and clicks exactly where i have clicked on the image, but the problem is when i resize the image to 100% height and width, the offset is not accurate anymore:
$('#screen').on('click', function(e) {
var offset = $(this).offset();
const relativeX = e.pageX - offset.left
const relativeY = e.pageY - offset.top
console.log('X: '+relativeX+'\nY: '+relativeY)
})
#screen {
width: 100%;
height: 100%;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<img id="screen" src="https://i.ibb.co/9brxVbK/image-2020-12-16-081145.png">
Lets say i want to click on the buttons on the left, it will click out of the window bounds.
How can i resize the image and get exactly the real offset?