This repository has been archived by the owner on Mar 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
242 lines (206 loc) · 5.43 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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<!DOCTYPE HTML>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>JS — Loader</title>
<meta name="author" content="Studio Meta">
<meta name="copyright" content="© Studio Meta">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=yes">
<link rel="shortcut icon" type="image/png" href="./icon.png">
<style type="text/css">
*, *:after, *:before { box-sizing: border-box; }
body {
margin: 0;
font: 1em/1.45 Arial, sans-serif;
text-align: center;
color: #222;
}
main {
width: 100%;
max-width: 42em;
margin: 6em auto 8em;
padding: 1em;
}
p { margin: 2.3em auto; }
a:not([class]) {
color: inherit;
text-decoration: none;
border-bottom: 1px solid;
}
h1, h2, h3, h4 {
margin: 2.414em 0 1.5em;
line-height: 1.2;
}
h1 {
margin-top: 0;
margin-bottom: 0;
line-height: 1;
font-size: 3.157em;
}
h2 { font-size: 2.369em; }
h3 { font-size: 1.777em; }
h4 { font-size: 1.333em; }
small { font-size: 0.75em; }
.icon {
display: inline-block;
vertical-align: middle;
margin-top: -1px;
margin-right: 0.25em;
fill: currentColor;
}
.icon-facebook { width: 0.5712890625em; }
.icon-twitter { width: 0.9287109375em; }
.icon-pinterest { width: 0.7138671875em; }
button {
display: inline-block;
margin: 0 0.5em;
padding: 0.5em 1em;
font: inherit;
font-weight: 700;
color: inherit;
-webkit-appearance: none;
background: none;
border: 3px solid;
cursor: pointer;
transition: background 0.2s ease-out;
}
button:hover { color: #111; }
button:focus { outline: 2px solid -webkit-focus-ring-color;}
button:active { transform: translate(0, 1px); }
.studiometa {
display: inline-block;
padding: 0.5em;
}
.studiometa span { display: block; }
.l {
position: relative;
margin: auto;
width: 20px;
height: 14px;
overflow: hidden;
}
.l-c-1,
.l-c-2,
.l-r-1,
.l-r-2 {
position: absolute;
background: #aaa;
}
.l-c-1,
.l-c-2 {
left: 0;
width: 6px;
height: 6px;
border-radius: 3px;
}
.l-c-1 { top: 0; }
.l-c-2 { top: 8px; }
.l-r-1,
.l-r-2 {
top: 0;
width: 4px;
height: 14px;
}
.l-r-1 { left: 9px; }
.l-r-2 { left: 16px; }
.percentage {
line-height: 1.8;
background: #eee;
}
.percentage,
.percentage span:last-child {
position: relative;
}
.percentage-bar {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: #ccc;
transform: scale(0, 1);
transform-origin: top left;
transition: all 0.3s ease-in-out;
}
img {
display: block;
width: 100%;
height: auto;
}
</style>
</head>
<body>
<main>
<section>
<h1>JS — Loader</h1>
<p>A script that simulates a loader by loading one image after another. It allows you to run a callback after each image loaded and when all images are loaded.</p>
<p>Used for the loader on <a href="http://signesduquotidien.org/" title="Signes du quotidien" target="_blank">Signes du quotidien</a>.</p>
<p>
<button type="button" id="js-add-images">Load pictures</button>
</p>
<p class="percentage">
<span class="percentage-bar" id="js-percentage-bar"></span>
<span id="js-percentage-text">0%</span>
</p>
</section>
<section id="js-images-container"></section>
<section>
<p>
<a class="studiometa" href="http://www.studiometa.fr/" target="_blank" title="Studio Meta, Agence Web Strasbourg">
<span class="l">
<span class="l-c-1"></span>
<span class="l-c-2"></span>
<span class="l-r-1"></span>
<span class="l-r-2"></span>
</span>
</a>
</p>
</section>
</main>
<script defer src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script defer src="./dist/loader.min.js"></script>
<script defer>
document.addEventListener('DOMContentLoaded', function() {
var btn = document.getElementById('js-add-images');
var bar = document.getElementById('js-percentage-bar');
var txt = document.getElementById('js-percentage-text');
var container = document.getElementById('js-images-container');
btn.addEventListener('click', function() {
// Prevent multiple click
this.style.pointerEvents = 'none';
$.ajax({
url: './images.html'
})
.done(function(data) {
// Get all the images in an array
var el = document.createElement('div');
el.innerHTML = data;
var images = el.querySelectorAll('img');
// Create a new loader
var loader = new Loader(images, {
attr: 'data-src',
onImageLoad: function(percentage) {
bar.style.transform = 'scale(' + percentage/100 + ', 1)';
txt.innerHTML = percentage + '%';
},
onComplete: function() {
var L = this;
// Append data only when the loader
// is finished animating
bar.addEventListener('transitionend', function() {
container.innerHTML = data;
var images = container.querySelectorAll('img');
for (var i = 0; i < images.length; i++) {
images[i].src = images[i].getAttribute(L.attr);
images[i].removeAttribute(L.attr);
}
});
}
});
});
});
});
</script>
</body>
</html>