You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 2-ui/2-events/01-introduction-browser-events/04-move-ball-field/solution.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -33,7 +33,7 @@ We have `event.clientX/clientY` -- window-relative coordinates of the click.
33
33
To get field-relative `left` coordinate of the click, we can substract the field left edge and the border width:
34
34
35
35
```js
36
-
let left =event.clientX-fieldInnerCoords.left-field.clientLeft;
36
+
let left =event.clientX-fieldCoords.left-field.clientLeft;
37
37
```
38
38
39
39
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.
43
43
So the final `left` would be:
44
44
45
45
```js
46
-
let left =event.clientX-fieldInnerCoords.left-field.clientLeft-ball.offsetWidth/2;
46
+
let left =event.clientX-fieldCoords.left-field.clientLeft-ball.offsetWidth/2;
47
47
```
48
48
49
49
The vertical coordinate is calculated using the same logic.
0 commit comments