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
The code won't work reliably while `<img>` has no width/height:
30
32
31
33
```html
32
34
<img src="ball.png" id="ball">
33
35
```
36
+
````
34
37
35
38
When the browser does not know the width/height of an image (from tag attributes or CSS), then it assumes them to equal `0` until the image finishes loading.
36
39
37
-
After the first load browser usually caches the image, and on next loads it will have the size immediately. But on the first load the value of `ball.offsetWidth` is `0`. That leads to wrong coordinates.
40
+
So the value of `ball.offsetWidth` will be `0` until the image loads. That leads to wrong coordinates in the code above.
41
+
42
+
After the first load, the browser usually caches the image, and on reloads it will have the size immediately. But on the first load the value of `ball.offsetWidth` is `0`.
38
43
39
44
We should fix that by adding `width/height` to `<img>`:
0 commit comments