-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
51 lines (44 loc) · 1.75 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<!-- Load Babel -->
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
</head>
<body>
<div id="output"></div>
<script src="dist/preload.min.js"></script>
<!-- Your custom script here -->
<script data-plugins="transform-es2015-modules-umd" type="text/babel">
import preload from '@bautrukevich/preload';
const IMAGE_URL = 'https://www.google.ru/images/branding/googlelogo/2x/googlelogo_color_120x44dp.png';
const FAILED_IMAGE_URL = 'https://www.google.ru/images/branding/googlelogo/2x.jpg';
let orImageWithSrc = new Image();
let orImageWithoutSrc = new Image(); // it's valid and you can set src later
orImageWithSrc.src = IMAGE_URL;
// It would be resolved
preload(IMAGE_URL, orImageWithSrc).then(resolved => {
console.log(resolved); // [[HTMLImageElement, 'loaded'], [HTMLImageElement, 'loaded']]
}, rejected => {
console.log(rejected);
});
// It would be rejected
preload(orImageWithoutSrc).then(resolved => {
console.log(resolved);
}, rejected => {
console.log(rejected); // [[HTMLImageElement, 'new']]
});
// It would be rejected — if at least one image was not loaded
preload(IMAGE_URL, orImageWithoutSrc).then(resolved => {
console.log(resolved);
}, rejected => {
console.log(rejected); // [[HTMLImageElement, 'loaded'], [HTMLImageElement, 'new']]
});
// It would be rejected — if at least one image was not loaded
preload(FAILED_IMAGE_URL, orImageWithSrc).then(resolved => {
console.log(resolved);
}, rejected => {
console.log(rejected); // [[HTMLImageElement, 'failed'], [HTMLImageElement, 'loaded']]
});
</script>
</body>