Changed 'fieldInnerCoords' to 'fieldCoords' to match image and text

This commit is contained in:
simmayor 2018-12-08 20:44:22 -05:00
parent 23b5766b82
commit efbf871daf

View file

@ -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.