This commit is contained in:
Ilya Kantor 2019-10-10 17:29:27 +03:00
parent 7418213b66
commit 6d44c1e1ac
5 changed files with 7 additions and 8 deletions

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Before After
Before After

View file

@ -22,7 +22,7 @@ Then the ball will be positioned relatively to the field:
}
```
Next we need to assign the correct `ball.style.position.left/top`. They contain field-relative coordinates now.
Next we need to assign the correct `ball.style.left/top`. They contain field-relative coordinates now.
Here's the picture:
@ -36,7 +36,7 @@ To get field-relative `left` coordinate of the click, we can substract the field
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, not center, would be under the mouse cursor.
Normally, `ball.style.left` means the "left edge of the element" (the ball). So if we assign that `left`, then the ball edge, not center, would be under the mouse cursor.
We need to move the ball half-width left and half-height up to make it center.