Merge pull request #663 from simmayor/introduction-browser-events

01-introduction-browser-events - Changed 'fieldInnerCoords' to 'fieldCoords' to match image and text
This commit is contained in:
Ilya Kantor 2018-12-15 19:01:17 +03:00 committed by GitHub
commit abe68e24c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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.