我有一組動態的 div,我希望它們以不同的順序排列。所以我flex order用來控制div的順序。其中一個 div 包含影像。通過單擊該影像,它應該控制與影像相關的單擊的 x 和 y 坐標。我已經做了我想要的一切。但問題是我得到的 y 坐標是負數,我相信這是因為我使用 flex 更改了順序。
這是我嘗試過的
預期結果:當我單擊邊框影像左上角位置時,它應該控制與影像相關的單擊的確切位置。
uj5u.com熱心網友回復:
這是您自己的計算造成的。您可以使用此功能簡化計算
GetMousePositionRelativeToTarget(e) {
// Get the target
const target = e.target;
// Get the bounding rectangle of target
const rect = target.getBoundingClientRect();
// Mouse position
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
console.log(x ':' y);
return [x, y];
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/471225.html
標籤:javascript 有角度的 打字稿
下一篇:顯示頁眉和隱藏頁腳減慢
