forked from farinspace/jquery.imgpreload
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.html
115 lines (76 loc) · 2.5 KB
/
demo.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Demo</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js"></script>
<script type="text/javascript" src="jquery.imgpreload.min.js"></script>
<script type="text/javascript">
jQuery(function($)
{
$('#status, #domstatus').append('<li> dom ready </li>');
});
// cache buster
var t = (new Date).getTime();
var the_images = [];
the_images.push( 'http://farm7.static.flickr.com/6195/6130724163_9ec1db80c7_b.jpg?i=1&t=' + t );
the_images.push( 'http://farm7.static.flickr.com/6188/6131273938_c711a28586_b.jpg?i=2&t=' + t );
the_images.push( 'http://farm7.static.flickr.com/6065/6125251344_c6f089b09f_b.jpg?i=3&t=' + t );
the_images.push( 'http://farm5.static.flickr.com/4001/4626549119_6c524ace61_b.jpg?i=4&t=' + t );
the_images.push( 'http://farm6.static.flickr.com/5229/5637847279_3acce67b5f_b.jpg?i=5&t=' + t );
the_images.push( 'fake-image.jpg?i=6&t=' + t );
jQuery.imgpreload(the_images,
{
each: function()
{
var pattern = new RegExp( "i=(\\d)", "gi" );
var m = pattern.exec($(this).attr('src'));
var status = $(this).data('loaded')?'success':'error';
$('#status').append('<li>' + m[1] + ': ' + $(this).attr('src') + ' ' + status + '</li>');
},
all: function()
{
$('#status').append('<li> all images loaded </li>');
}
});
</script>
</head>
<body>
<h3>Status:</h3>
<ul id="status"></ul>
<h3>In-dom status:</h3>
<ul id="domstatus"></ul>
<div id="images" style="display:none;">
<script type="text/javascript">
// cache buster
var t = (new Date).getTime();
var icnt = the_images.length;
for (var i=0; i<icnt; i++)
{
the_images[i] = the_images[i].replace(/t=\d*/gi, 't=' + t);
document.write('<img src="' + the_images[i] + '" alt=""/>');
}
</script>
</div>
<script type="text/javascript">
jQuery(function($)
{
$('#images img').imgpreload
({
each: function()
{
var pattern = new RegExp( "i=(\\d)", "gi" );
var m = pattern.exec($(this).attr('src'));
var status = $(this).data('loaded')?'success':'error';
$('#domstatus').append('<li>' + m[1] + ': ' + $(this).attr('src') + ' ' + status +'</li>');
$(this).addClass('image-loaded');
},
all: function()
{
$('#domstatus').append('<li> all images loaded </li>');
}
});
});
</script>
</body>
</html>