improve x and y position
This commit is contained in:
parent
97cdb093a5
commit
608ba5cc6f
@ -53,9 +53,20 @@ function Preview({ code, device }: Props) {
|
||||
// Highlight the selected element
|
||||
updateHighlight(targetElement);
|
||||
|
||||
// Show popup at click position
|
||||
// Show popup at click position, slightly offset to be right under the cursor
|
||||
setPopupVisible(false);
|
||||
setPopupPosition({ x: clientX, y: clientY });
|
||||
|
||||
// Calculate offsets
|
||||
const rect = iframeRef.current?.getBoundingClientRect();
|
||||
const offsetX = rect ? rect.left : 0;
|
||||
const offsetY = rect ? rect.top : 0;
|
||||
|
||||
// Adjust for scale
|
||||
const scale = 1; // the scale factor applied to the iframe
|
||||
const scaledX = clientX / scale + offsetX;
|
||||
const scaledY = clientY / scale + offsetY;
|
||||
|
||||
setPopupPosition({ x: scaledX, y: scaledY });
|
||||
setPopupVisible(true);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user