-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.html
835 lines (727 loc) · 27.1 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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width">
<title>LaziestLoader, a responsive and retina-aware lazy loader for jQuery</title>
</head>
<style>
body {
background: #FDFAF2;
color: #555;
font-family:"Helvetica Neue", sans-serif;
font-weight: 300;
font-size: 16px;
line-height: 1.4em;
padding: 15px 30px 60px 30px;
margin: 0 auto;
max-width: 1400px;
}
h1 {
font-size: 37px;
line-height: 40px;
margin: 0 0 18px 0;
}
h2 {
color: #333;
font-size: 19px;
line-height: 21px;
margin: 0 0 7px 0;
}
h2 span {
font-style: italic;
}
h3 {
font-size: 14px;
line-height: 16px;
margin: 3px 0 1px 0;
}
h4 {
color: #313131;
font-size: 11px;
line-height: 11px;
text-transform: uppercase;
margin: 20px 0 7px 0;
}
p {
font-size: 14px;
line-height: 19px;
margin: 0 0 16px 0;
}
a {
color: #965131;
}
ol {
list-style: decimal-leading-zero;
color: #000;
font-size: 13px;
padding-left: 28px;
margin: 0;
}
ol ul, ul ul, ol ol {
margin-bottom: 10px;
}
section {
width: 100%;
max-width: 560px;
margin-bottom: 30px;
}
section.examples{
max-width: 100%;
}
@media all and (min-width: 768px) {
section{
margin-bottom: 60px;
}
}
.intro {
color: #000;
max-width: 670px;
margin-bottom: 30px;
}
.intro p {
font-size: 17px;
line-height: 21px;
margin-bottom: 0;
}
.example{
margin: 0 0 33px 0;
}
.example > p {
max-width: 560px;
margin: 0 0 9px 0;
}
.example > img, .example > video, .example > iframe {
display: block;
width: 100%;
}
.example.small {
width: 60%;
}
code, .code {
display: block;
max-width: 600px;
margin: 20px 0;
padding: 6px 10px;
border-radius: 3px;
text-align: left;
background-color: #535353;
border: 1px solid #000000;
font-size: 13px;
line-height: 19px;
overflow: auto;
font-family: courier;
font-size: 12px;
color: #fff;
}
li .code {
display: inline;
padding: 1px 3px;
}
.example code, .example .code{
max-width: 900px;
}
.message {
position: fixed;
-webkit-transform: translateZ(0);
width: 100%;
left: 0;
bottom: 0;
color: #000;
font-size: 11px;
font-weight: bold;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
z-index: 11;
border-top: 0px solid #000;
background-color: #CCCAC3;
padding: 0px 10px;
height: 0;
transition: all 0.4s ease;
}
.message.active {
border-top-width: 1px;
padding: 8px 10px;
height: auto;
}
.message > p {
font-size: 11px;
display: inline-block;
margin: 0;
}
.message p .kicker {
color: #000;
font-weight: normal;
padding-right: 8px;
text-transform: uppercase;
}
#justloaded {
visibility: hidden;
margin-left: 15px;
}
@media all and (min-width: 700px) {
#justloaded {
visibility: visible;
}
}
@-webkit-keyframes pulse {
0% {
background-color: #45CEEF;
}
25% {
background-color: #FFF5A5;
}
50% {
background-color: #FFD4DA;
}
75% {
background-color: #99D2E4;
}
100% {
background-color: #D8CAB4;
}
}
#forkongithub a {
background:#000;
color:#fff;
text-decoration:none;
font-family:arial, sans-serif;
text-align:center;
font-weight:bold;
padding:5px 40px;
font-size:1rem;
line-height:2rem;
position:relative;
transition:0.5s;
}
#forkongithub a:hover {
background:#060;
color:#fff;
}
#forkongithub a::before, #forkongithub a::after {
content:"";
width:100%;
display:block;
position:absolute;
top:1px;
left:0;
height:1px;
background:#fff;
}
#forkongithub a::after {
bottom:1px;
top:auto;
}
@media screen and (min-width:800px) {
#forkongithub {
position:fixed;
display:block;
top:0;
right:0;
width:200px;
overflow:hidden;
height:200px;
}
#forkongithub a {
width:200px;
position:absolute;
top:60px;
right:-60px;
transform:rotate(45deg);
-webkit-transform:rotate(45deg);
box-shadow:3px 4px 10px rgba(0, 0, 0, 0.8);
}
}
#releasehistory h4{
margin: 0 0 3px 0;
}
#releasehistory ul{
margin: 0 0 11px 0;
padding: 0px;
}
#releasehistory li{
font-size: 13px;
line-height: 15px;
margin: 0 0 3px 0;
padding: 0;
list-style-type: none;
}
</style>
<body>
<div id="status" class="message">
<p>
<span class="kicker">Elements loaded</span>
<span id="total"></span>
</p>
<p id="justloaded"></p>
</div>
<section class="intro">
<h1>LaziestLoader</h1>
<p>Speed up your responsive and retina-aware website with LaziestLoader, a jQuery plugin that loads, from an array of sources, the most appropriate image at the last possible moment, and updates the image after a resize if needed. Custom callbacks and configuration provide even more functionality, like loading non-image elements and generic scroll-based triggers.</p>
</section>
<section class="installation">
<h2>Download v0.7.2</h2>
<ol>
<li><a href="https://raw.githubusercontent.com/sjwilliams/laziestloader/v0.7.2/jquery.laziestloader.js">Development Version</a></li>
<li><a href="https://raw.githubusercontent.com/sjwilliams/laziestloader/v0.7.2/jquery.laziestloader.min.js">Production Version</a></li>
<li><span class="code">$ npm install laziestloader</span></li>
<li><span class="code">$ bower install laziestloader</span></li>
</ol>
</section>
<section class="prep">
<h2>Image Prep</h2>
<p>Your web-ready files need to be structured so that the name or path includes the <em>width</em> or a <em>slug</em> that represents the width.</p>
<h4>Examples</h4>
<ol>
<li>
<ul>
<li>/images/pony-1300.jpg</li>
<li>/images/pony-900.jpg</li>
<li>/images/pony-640.jpg</li>
</ul>
</li>
<li>
<ul>
<li>/images/pony/1300.jpg</li>
<li>/images/pony/900.jpg</li>
<li>/images/pony/640.jpg</li>
</ul>
</li>
<li>
<ul>
<li>/images/1300/PONY-1300.jpg</li>
<li>/images/900/PONY-900.jpg</li>
<li>/images/640/PONY-640.jpg</li>
</ul>
</li>
<li>
<ul>
<li>/images/pony-large.jpg</li>
<li>/images/pony-medium.jpg</li>
<li>/images/pony-small.jpg</li>
</ul>
</li>
<li>
<ul>
<li>/images/pony/large.jpg</li>
<li>/images/pony/medium.jpg</li>
<li>/images/pony/small.jpg</li>
</ul>
</li>
</ol>
<h4>Retina</h4>
<p>Retina images are also supported with either pattern. You can use whatever naming convention you like to specify the retina source.</p>
<ol>
<li>
<ul>
<li>/images/[email protected]</li>
<li>/images/[email protected]</li>
<li>/images/[email protected]</li>
</ul>
</li>
<li>
<ul>
<li>/images/retina-large/pony.jpg</li>
<li>/images/retina-medium/pony.jpg</li>
<li>/images/retina-small/pony.jpg</li>
</ul>
</li>
</ol>
</section>
<section class="prep">
<h2>HTML/CSS Prep</h2>
<p>Your image element should include a default image. A 1px transparent png or gif will work fine. You may also want to add a class to simplify your jQuery selector in a moment.</p>
<code><img class="lazy" src="img/transparent.gif"></code>
<p>LaziestLoader works by finding the best-sized source image to match the target image element's current width. Since "img" elements are inline elements, they'll only have as much width at the current image, which will most likely be very small, like a 1px transparent gif. To ensure the plugin works correctly, you need to make sure the "img" element reports the width you want it to be. One way is to force it to fill its container element with CSS.</p>
<code>
img.lazy{
display:block;
width: 100%;
}
</code>
</section>
<section class="examples">
<h2>Example Usage</h2>
<div class="example">
<h3>Non-responsive</h3>
<p>The most basic method simply sets the src attribute as the element enters the viewport.</p>
<img class="lazy" src="img/transparent.gif" data-src="http://dummyimage.com/1400x700/753e75/fff.png">
<pre class="code">
// html
<img class="lazy" src="img/transparent.gif" data-src="http://dummyimage.com/1400x700/753e75/fff.png">
// js
$('.lazy').laziestloader();
</pre>
</div>
<div class="example">
<h3>Non-responsive w/ Retina</h3>
<p>Specify a standard and an optional retina image.</p>
<img class="lazy" src="img/transparent.gif" data-src="http://dummyimage.com/1400x700/2a2a2a/fff.png" data-src-retina="http://dummyimage.com/2800x1400/2a2a2a/fff.png">
<pre class="code">
// html
<img class="lazy" src="img/transparent.gif" data-src="http://dummyimage.com/1400x700/2a2a2a/fff.png" data-src-retina="http://dummyimage.com/2800x1400/2a2a2a/fff.png">
// js
$('.lazy').laziestloader();
</pre>
</div>
<div class="example small">
<h3>Non-responsive w/ Retina, smaller element</h3>
<p>Basic example always loads the same image, regardess of element width.</p>
<img class="lazy" src="img/transparent.gif" data-src="http://dummyimage.com/1400x700/3a3a3a/fff.png" data-src-retina="http://dummyimage.com/2800x1400/3a3a3a/fff.png">
<pre class="code">
// html
<img class="lazy" src="img/transparent.gif" data-src="http://dummyimage.com/1400x700/3a3a3a/fff.png" data-src-retina="http://dummyimage.com/2800x1400/3a3a3a/fff.png">
// js
$('.lazy').laziestloader();
</pre>
</div>
<div class="example">
<h3>Responsive</h3>
<p>Go beyond a single source by providing a URL that has a width as part of the path or name.</p>
<img class="lazy" src="img/transparent.gif" data-pattern="img/ar-{{size}}.jpg" data-widths="[320, 900, 1500]">
<pre class="code">
// html
<img class="lazy" src="img/transparent.gif" data-pattern="img/ar-{{size}}.jpg" data-widths="[320, 900, 1500]">
// js
$('.lazy').laziestloader();
</pre>
</div>
<div class="example small">
<h3>Responsive, smaller element</h3>
<p>Load a smaller image, if possible.</p>
<img class="lazy" src="img/transparent.gif" data-pattern="img/ar-{{size}}.jpg" data-widths="[320, 900, 1500]">
<pre class="code">
// html
<img class="lazy" src="img/transparent.gif" data-pattern="img/ar-{{size}}.jpg" data-widths="[320, 900, 1500]">
// js
$('.lazy').laziestloader();
</pre>
</div>
<div class="example">
<h3>Responsive w/ Slugs</h3>
<p>You can select a sized image that doesn't use the width value in the file name or path.</p>
<img class="lazy" src="img/transparent.gif" data-pattern="img/ar2-{{size}}.jpg" data-widths='[{"size":320,"slug":"small"}, {"size":900, "slug":"medium"}, {"size":1500, "slug":"large"}]'>
<pre class="code">
// html
<img class="lazy" src="img/transparent.gif" data-pattern="img/ar2-{{size}}.jpg" data-widths='[{"size":320,"slug":"small"}, {"size":900, "slug":"medium"}, {"size":1500, "slug":"large"}]'>
// js
$('.lazy').laziestloader();
</pre>
</div>
<div class="example">
<h3>Callback</h3>
<p>Pass in a callback to excute custom code after the src attribute has been changed. That's how the updating "elements loaded" bar below works.</p>
<img class="lazy" src="img/transparent.gif" data-src="http://dummyimage.com/1400x700/5a5a5a/fff.png">
<pre class="code">
//html
<img class="callback" src="img/transparent.gif" data-src="http://dummyimage.com/1400x700/5a5a5a/fff.png">
// js
var totalLoaded = 0;
$("img.callback").laziestloader({ threshold: 100}, function() {
totalLoaded += 1;
$("#total").html(totalLoaded);
});
</pre>
</div>
<div class="example">
<h3>Custom Source Function</h3>
<p>Need fancier logic to determine the source path? You can write your own.</p>
<img class="custom" src="img/transparent.gif">
<pre class="code">
//html
<img class="custom" src="img/transparent.gif">
// js
$("img.custom").laziestloader({
threshold: 100,
getSource: function($el) {
var width = $el.width();
var height = Math.round(width * 0.5625);
return 'http://placekitten.com/'+width+'/'+height;
}
});
</pre>
</div>
<div class="example">
<h3>Best Fit</h3>
<p>The best-fit method used internally can also be used in your callbacks and custom source functions. Pass in a target width and an array of possible values to find the best value.</p>
<img class="bestfit" src="img/transparent.gif">
<pre class="code">
//html
<img class="bestfit" src="img/transparent.gif">
// js
$("img.bestfit").laziestloader({
threshold: 100,
getSource: function($el) {
var width = $().laziestloader.bestFit($el.width(), [200, 700, 900, 1200]);
var height = Math.round(width * 0.5625);
return 'http://placekitten.com/'+width+'/'+height;
}
});
</pre>
</div>
<div class="example">
<h3>Video</h3>
<p>Images aren't the only things with 'src' attributes. Try a video.</p>
<video class="lazy" autoplay loop data-pattern="http://joshwilliams.com/projects/sunset-flipbook/videos/bridge-{{size}}.mp4" data-widths="[640, 900]"></video>
<pre class="code">
// html
<video class="lazy" autoplay loop data-pattern="http://joshwilliams.com/projects/sunset-flipbook/videos/bridge-{{size}}.mp4" data-widths="[640, 900]"></video>
// js
$('.lazy').laziestloader();
</pre>
</div>
<div class="example">
<h3>Set Element Height Programmatically</h3>
<p>Often in responsive applications it's useful to set the height of an element before the source is loaded so the element will pre-fill the correct amount of space. In this example, because iFrames also have src attributes but need their sizes specified to be useful, we'll set the height via the plugin. The height is determined by multipling the element width by the 'data-ratio' vaule.
<em>Note: This example will not be responsive because the iFrame content from YouTube isn't smart enough to repsond to the changing viewport.</em>
</p>
<iframe class="iframe" data-src="//www.youtube.com/embed/fNlxKH9Jtmc" data-ratio="0.5625" frameborder="0" allowfullscreen></iframe>
<pre class="code">
// html
<iframe class="iframe" data-src="//www.youtube.com/embed/fNlxKH9Jtmc" data-ratio="0.5625" frameborder="0" allowfullscreen></iframe>
// js
$('.iframe').laziestloader({threshold:300});
</pre>
</div>
<div class="example">
<h3>Completely Custom Behavior /w Callback</h3>
<p>Need more control than custom source path generation? For example, you might want to completely rewrite the contents of your element. You can have your callback do all the work, sidestepping much of LaziestLoader's functionality.</p>
<div class="override"></div>
<pre class="code">
// html
<div class="override"></div>
// js
$('div.override').laziestloader({
threshold: 100,
setSourceMode: false // this is the important bit!
}, function(){
var height = Math.round($(this).width() * 0.5625);
$(this).html('<p style="text-align:center; height: '+height+'px; line-height:'+height+'px;-webkit-animation: pulse 10s infinite alternate;">Boom!</p>')
});
</pre>
</div>
</section>
<section>
<h2>Options</h2>
<p>In addition to the "Custom Source Function" using `getSource` example above, there are other optional behaviors that can be configured in the options object.</p>
<h3>threshold</h3>
<p>By default, images are only loaded when the user scrolls to them and they became visible on the screen.</p>
<p>If you want your images to load earlier than that, lets say 200px before they appear on the screen, specify the threshold in the options object.</p>
<code>
$("img").laziestloader({threshold: 200});
</code>
<h3>scrollThrottle</h3>
<p>To increase performance, the position of lazy loading elements are only checked every 250ms while scrolling. If you need to perform the check more often, lower the number. If scroll performance is an issue -- likely if there are lots of elements -- increase the number.</p>
<code>
$("img").laziestloader({scrollThrottle: 300});
</code>
<h3>sizeOffsetPercent</h3>
<p>The crop selection logic works by picking the image that is greater than or equal to the size of the current element. If you prefer to scale smaller images into larger elements, set this between 0 and 100, where the value is the percent width of the containing element you want to subtract from the math logic. The bigger the number, the smaller the image that'll be selected.
</p>
<code>
$("img").laziestloader({sizeOffsetPercent: 10});
</code>
<h3>sizePattern</h3>
<p>The regular expression used to search your string, to be replaced by the width number or slug. The default is `/{{SIZE}}/ig`, which finds the string `size`, regardless of case, inside of '{' style double brackets. Example: `/path/name-{{size}}.jpg`. Changing this option is useful if, for example, you have Mustache-style templates rendered on the server that would also match the default laziestloader.js pattern and be rendered blank before our client code runs. Many characters have special meaning and can't be used. A nice alternal pattern is:</p>
<code>
$("img").laziestloader({sizePattern: /%size%/ig});
</code>
<h3>setSourceMode</h3>
<p>In most cases, the plugin needs to set the source attribute of the element. If you want to use the plugin in ways that don't involve simply setting a source attribute, set `setSourceMode` to false and use the callback to completely manage the behavior of the element on trigger.</p>
<pre class="code">
<div><p>Replace me</p></div>
$('div').laziestloader({
setSourceMode: false
}, function(){
$(this).html('<div><p>New content</p></div>')
});
</pre>
</section>
<section>
<h2>Trigger</h2>
<p>You can trigger element loading without scrolling the element into view.</p>
<code>
$("img.lazy").trigger("laziestloader");
</code>
</section>
<section id="releasehistory">
<h2>Release History</h2>
<h4>0.7.3</h4>
<ul>
<li>Added "main": "jquery.laziestloader.js" to package.json</li>
</ul>
<h4>0.7.2</h4>
<ul>
<li>Removed stray console.log. Sorry.</li>
</ul>
<h4>0.7.1</h4>
<ul>
<li>Fixed bug in detecting if watched event should be native scroll.</li>
</ul>
<h4>0.7.0</h4>
<ul>
<li>Allow custom events, beyond the native scroll event, to trigger LaziestLoader. See <a href="https://github.com/sjwilliams/laziestloader/pull/16">Issue 16</a>.</li>
</ul>
<h4>0.6.3</h4>
<ul>
<li>Wait until $(document).ready() to perform initial check of lazy images.</li>
</ul>
<h4>0.6.2</h4>
<ul>
<li>Added a class of "ll-loadstarted" to indicte that media has started but, perhaps, hasn't finished downloading.</li>
</ul>
<h4>0.6.1</h4>
<ul>
<li>Correct copyright date.</li>
</ul>
<h4>0.6.0</h4>
<ul>
<li>Adding horizontal checks for sideways scrolling.</li>
</ul>
<h4>0.5.2</h4>
<ul>
<li>Tiny comment fix.</li>
</ul>
<h4>0.5.1</h4>
<ul>
<li>Loaded state fired, if possible, when media actually loads, not simply triggered by viewport position. See <a href="https://github.com/sjwilliams/laziestloader/issues/8">Issue 8</a>.</li>
</ul>
<h4>0.5.0</h4>
<ul>
<li>Classes added to element to reflect state. See <a href="https://github.com/sjwilliams/laziestloader/issues/8">Issue 8</a>.</li>
<li>Changed name of npm task that builds minifed version.</li>
</ul>
<h4>0.4.1</h4>
<ul>
<li>Correct link to production source.</li>
</ul>
<h4>0.4.0</h4>
<ul>
<li>Added minified version and npm build task to generate it.</li>
<li>Moved all documentation from README.md to redesigned project page.</li>
</ul>
<h4>0.3.0</h4>
<ul>
<li>Exposed `bestFit` method so it can be used in callbacks. See <a href="https://github.com/sjwilliams/laziestloader/issues/4">Issue 4</a>.</li>
</ul>
<h4>0.2.0</h4>
<ul>
<li>Added a scrollThrottle option, and set a reasonable default. See <a href="https://github.com/sjwilliams/laziestloader/issues/5">Issue 5</a>.</li>
<li>Changed data-height-multiplier to data-ratio, and deprecated original. See <a href="https://github.com/sjwilliams/laziestloader/issues/6">Issue 6</a>.</li>
</ul>
<h4>0.1.2</h4>
<ul>
<li>Fixed <a href="https://github.com/sjwilliams/laziestloader/issues/1">Issue 1</a>, bug with non-sorted input.</li>
</ul>
<h4>0.1.1</h4>
<ul>
<li>Added `sizePattern` option.</li>
</ul>
<h4>0.1.0</h4>
<ul>
<li>Added `sizeOffsetPercent` option.</li>
</ul>
<h4>0.0.2</h4>
<ul>
<li>AMD module</li>
<li>Enforce style with .editorconfig, .jshintrc and .jsbeautifyrc</li>
</ul>
<h4>0.0.1</h4>
<ul>
<li>Initial release.</li>
</ul>
</section>
<section>
<h2>Credits</h2>
<p>LaziestLoader is by <a href="http://joshwilliams.com">Josh Williams</a>. Inspried by Luís Almeida's <a href="http://luis-almeida.github.com/unveil/">unveil</a></p>
</section>
<section>
<h2>License</h2>
<p>LaziestLoader is licensed under the <a href="https://raw.githubusercontent.com/sjwilliams/laziestloader/master/LICENSE">MIT license</a></p>
</section>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
window.jQuery || document.write('<script src="jquery-1.9.1.min.js"><\/script>')
</script>
<script src="jquery.laziestloader.js"></script>
<script>
$(function() {
var totalLoaded = 0;
var $w = $(window),
$status = $('#status'),
$examplesContainer = $('.examples');
var didScroll = false;
var cb = function() {
totalLoaded += 1;
var src = ($(this).attr('src')) ? $(this).attr('src') : 'Custom content';
$('#justloaded').show().html('<span class="kicker">Loading</span>' + src).stop(true, true).delay(700).fadeOut(1500);
$('#total').html(totalLoaded);
};
var showStatus = function() {
if ($w.scrollTop() > $examplesContainer.offset().top) {
$status.addClass('active');
} else {
$status.removeClass('active');
}
};
$w.scroll(function() {
didScroll = true;
});
setInterval(function() {
if (didScroll) {
didScroll = false;
showStatus();
}
}, 100);
// standard methods
$('.lazy').laziestloader({
threshold: 300
}, cb);
// iframe
$('.iframe').laziestloader({
threshold: 300,
setHeight: true
}, cb);
// custom methods
$('img.custom').laziestloader({
threshold: 100,
getSource: function($el) {
var width = $el.width();
var height = Math.round(width * 0.5625);
return 'http://placekitten.com/' + width + '/' + height;
}
}, cb);
// override
$('div.override').laziestloader({
threshold: 100,
setSourceMode: false
}, function() {
cb.call(this);
var height = Math.round($(this).width() * 0.5625);
$(this).html('<p style="text-align:center; height: ' + height + 'px; line-height:' + height + 'px;-webkit-animation: pulse 10s infinite alternate;">Boom!</p>')
});
$('img.bestfit').laziestloader({
threshold: 100,
getSource: function($el) {
var width = $().laziestloader.bestFit($el.width(), [200, 700, 900, 1200]);
var height = Math.round(width * 0.5625);
return 'http://placekitten.com/' + width + '/' + height;
}
}, cb);
});
</script>
<div id="forkongithub"><a href="https://github.com/sjwilliams/laziestloader">Fork me on GitHub</a></div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-1861183-13', 'sjwilliams.github.io');
ga('send', 'pageview');
</script>
</body>
</html>