Skip to content

Commit

Permalink
this time the bug is absolutely fix!: display offset of the red point…
Browse files Browse the repository at this point in the history
…s in the generated image and the green points of the actual clicks.!
  • Loading branch information
creeponsky committed Apr 9, 2023
1 parent 53ca8e3 commit 09119b5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 38 deletions.
39 changes: 20 additions & 19 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,27 @@ $(document).ready(function () {
let img = document.getElementById('clickable-image') as HTMLImageElement;
$('#clickable-image').on('click', function (event) {
const img = $(this);
const offset = img.offset();

if (offset) {
const x = event.pageX - offset.left;
const y = event.pageY - offset.top;
points.push({ x: x, y: y });

const point = $('<div class="point"></div>');
point.css({
left: x + 'px',
top: y + 'px',
});
$('#image-container').append(point);

console.log('Clicked at', x, y);
console.log('Current points:', points);

const x = event.offsetX;
const y = event.offsetY;

// 确保点击点在图片范围内
if (x < 0 || x > img.width()! || y < 0 || y > img.height()!) {
return;
}
});

points.push({ x: x, y: y });

const point = $('<div class="point"></div>');
point.css({
left: x + 'px',
top: y + 'px',
});
$('#image-container').append(point);

console.log('Clicked at', x, y);
console.log('Current points:', points);
});

// Automatically submit the form when a file is selected
$('#image').on('change', function () {
Expand Down Expand Up @@ -78,8 +81,6 @@ $(document).ready(function () {
});
$('#output-image-container').empty().append(imgElement);
}



function getDisplayedImageSize(image: HTMLImageElement) {
return {
Expand Down
24 changes: 5 additions & 19 deletions static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,16 @@ img {

#image-container,
#output-image-container {
overflow: hidden;
background-color: black;
}

#clickable-image,
#output-image {
max-width: 100%;
max-height: 100%;
object-fit: contain;
}

#image-container {
position: relative;
display: inline-block;
width: 45%;
width: 600px;
height: 600px;
background-color: lightgrey;
overflow: hidden;
}

#clickable-image {
cursor: crosshair;
max-width: 100%;
height: 100%;
#clickable-image,
#output-image {
max-width: 700px;
max-height: 600px;
object-fit: contain;
}

Expand Down

0 comments on commit 09119b5

Please sign in to comment.