Changed 'fieldInnerCoords' to 'fieldCoords' to match image and text
This commit is contained in:
parent
23b5766b82
commit
efbf871daf
1 changed files with 2 additions and 2 deletions
|
@ -33,7 +33,7 @@ We have `event.clientX/clientY` -- window-relative coordinates of the click.
|
|||
To get field-relative `left` coordinate of the click, we can substract the field left edge and the border width:
|
||||
|
||||
```js
|
||||
let left = event.clientX - fieldInnerCoords.left - field.clientLeft;
|
||||
let left = event.clientX - fieldCoords.left - field.clientLeft;
|
||||
```
|
||||
|
||||
Normally, `ball.style.position.left` means the "left edge of the element" (the ball). So if we assign that `left`, then the ball edge would be under the mouse cursor.
|
||||
|
@ -43,7 +43,7 @@ We need to move the ball half-width left and half-height up to make it center.
|
|||
So the final `left` would be:
|
||||
|
||||
```js
|
||||
let left = event.clientX - fieldInnerCoords.left - field.clientLeft - ball.offsetWidth/2;
|
||||
let left = event.clientX - fieldCoords.left - field.clientLeft - ball.offsetWidth/2;
|
||||
```
|
||||
|
||||
The vertical coordinate is calculated using the same logic.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue