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/5-loading/03-onload-onerror/1-load-img-callback/task.md
+11-11Lines changed: 11 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -2,35 +2,35 @@ importance: 4
2
2
3
3
---
4
4
5
-
# Load images with a callback
5
+
# Завантажте зображення з колбеком
6
6
7
-
Normally, images are loaded when they are created. So when we add`<img>`to the page, the user does not see the picture immediately. The browser needs to load it first.
7
+
Зазвичай зображення завантажуються під час їх створення. Тому, коли ми додаємо`<img>`на сторінку, користувач не відразу бачить зображення. Спочатку його потрібно завантажити браузеру.
8
8
9
-
To show an image immediately, we can create it "in advance", like this:
9
+
Щоб відразу показати зображення, ми можемо створити його "заздалегідь", наприклад:
10
10
11
11
```js
12
12
let img =document.createElement('img');
13
13
img.src='my.jpg';
14
14
```
15
15
16
-
The browser starts loading the image and remembers it in the cache. Later, when the same image appears in the document (no matter how), it shows up immediately.
16
+
Браузер починає завантажувати зображення і запам’ятовує його в кеші. Пізніше, коли те саме зображення з’являється в документі (незалежно від того, як), воно з’являється негайно.
17
17
18
-
**Create a function `preloadImages(sources, callback)` that loads all images from the array `sources`and, when ready, runs`callback`.**
18
+
**Створіть функцію `preloadImages(sources, callback)`, яка завантажує всі зображення з масиву `sources`і, коли буде готова, запускає`callback`.**
19
19
20
-
For instance, this will show an `alert` after the images are loaded:
20
+
Наприклад, після завантаження зображень буде відображатися `alert`:
In case of an error, the function should still assume the picture "loaded".
30
+
У разі помилки функція все одно повинна вважати картинку "завантаженою".
31
31
32
-
In other words, the `callback`is executed when all images are either loaded or errored out.
32
+
Іншими словами, `callback`виконується, коли всі зображення завантажуються або є помилка.
33
33
34
-
The function is useful, for instance, when we plan to show a gallery with many scrollable images, and want to be sure that all images are loaded.
34
+
Ця функція корисна, наприклад, коли ми плануємо показати галерею з великою кількістю зображень, які можна прокручувати, і хочемо бути впевненими, що всі зображення завантажені.
35
35
36
-
In the source document you can find links to test images, and also the code to check whether they are loaded or not. It should output`300`.
36
+
У вихідному документі ви можете знайти посилання на тестові зображення, а також код, щоб перевірити, завантажені вони чи ні. Він має вивести`300`.
0 commit comments