forked from luis-almeida/unveil
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
194 lines (172 loc) · 9.25 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="description" content="Filtrify">
<meta name="keywords" content="javascript, jquery, lazy load, performance, plugin" />
<meta name="author" content="Luís Almeida">
<meta name="viewport" content="width=device-width">
<title>jQuery Unveil - A very lightweight plugin to lazy load images</title>
</head>
<style>
body {
background: #FFF;
color: #555;
font-family: "Helvetica Neue", sans-serif;
font-weight: 300;
line-height: 1.7;
padding: 30px 30px 300px 30px;
margin: 0 auto;
max-width: 480px;
}
header {
margin: 100px 0;
}
header p {
color: #CCC;
margin: 0 0 25px 0;
}
header h1 {
color: #000;
font-size: 75px;
line-height: 1;
margin: 0 0 10px 0;
}
header h1 small{
font-size: 16px;
}
h2 {
color: #333;
margin-top: 100px;
font-size: 1em;
}
p {
margin: 15px auto;
}
a {
color: #3595b5;
}
strong {
font-size: 1.5em;
color: #CCC;
}
code {
}
code > span.red {
color: #D14;
}
code > span.blue {
color: #099;
}
ul {
list-style: none;
padding: 0;
}
ul > li {
margin-top: 50px;
text-align: center;
}
ul > li > img {
display: inline-block;
max-width: 100%;
}
.twitter-share-button {
margin-left: 20px;
}
.big {
width: 3000px;
text-align: right;
}
.big img {
margin: auto 0 auto auto;
}
</style>
<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.unveil.js"></script>
<script>
$(function() {
$("li img").unveil(300);
$(".vertical img").unveil(300);
$(".horizontal img").unveil(300, { horizontal : true });
});
</script>
<body>
<header>
<h1>Unveil<small>.js</small></h1>
<p>Lightway version of Lazy Load with support for serving<br> high-resolution images to devices with retina displays</p>
<iframe src="http://ghbtns.com/github-btn.html?user=luis-almeida&repo=unveil&type=watch" allowtransparency="true" frameborder="0" scrolling="0" width="55" height="20"></iframe>
<iframe src="http://ghbtns.com/github-btn.html?user=luis-almeida&repo=unveil&type=fork" allowtransparency="true" frameborder="0" scrolling="0" width="55" height="20"></iframe>
<a href="https://twitter.com/share" class="twitter-share-button" data-text="unveil.js - A very lightweight plugin to lazy load images" data-via="lmgalmeida" data-related="lmgalmeida" data-count="none">Tweet</a>
</header>
<p>Most of us are familiar with the <a target="_blank" href="http://www.appelsiini.net/projects/lazyload">Lazy Load</a> plugin by <a target="_blank" href="http://www.appelsiini.net/">Mika Tuupola</a>.
<p>This plugin is very useful and it boosts performance delaying loading of images in long web pages because images outside of viewport (visible part of web page) won't be loaded until the user scrolls to them.</p>
<p>Lazy Load has some cool options such as custom effects, container, events or data attribute. If you're not gonna use any of them you can reduce the file size by leaving just the essential code to show the images.</p>
<p>That's what I did and this is my lightweight version of Lazy Load with support for serving high-resolution images to devices with retina displays - <strong>less than 1k</strong>.</p>
<h2>Usage</h2>
<p>Use a placeholder image in the src attribute - something to be displayed while the original image loads - and include the actual image source in a "data-src" attribute.</p>
<p>If you want to serve high-resolution images to devices with retina displays, you just have to include the source for those images in a "data-src-retina" attribute.</p>
<p>You don't need to include a "data-src-retina" attribute in all the image tags, unveil is smart enough to fallback to "data-src" or even do nothing in case there isn't any "data-src" specified.</p>
<code><img <span class="blue">src=</span><span class="red">"bg.png"</span> <span class="blue">data-src=</span><span class="red">"img1.jpg"</span> /></code>
<br>
<code><img <span class="blue">src=</span><span class="red">"bg.png"</span> <span class="blue">data-src=</span><span class="red">"img2.jpg"</span> <span class="blue">data-src-retina=</span><span class="red">"img2-retina.jpg"</span> /></code>
<br>
<p>If you care about users without javascript enabled, you can include the original image inside a <noscript> tag:</p>
<code><noscript><br> <img <span class="blue">src=</span><span class="red">"img1.jpg"</span> /><br></noscript></code>
<br><br>
<p>Run the script on document ready:</p>
<code>$(<span class="blue">document</span>).ready(<span class="blue">function</span>() {<br>
$(<span class="red">"img"</span>).unveil();<br>
});</code>
<h2>Options</h2>
<p>By default, images are only loaded and "unveiled" 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, you just have to:</p>
<code>$(<span class="red">"img"</span>).unveil(<span class="blue">200</span>);</code>
<h2>Trigger</h2>
<p>You can still trigger image loading whenever you need.</p>
<p>All you have to do is select the images you want to "unveil" and trigger the event:</p>
<code>$(<span class="red">"img"</span>).trigger(<span class="blue">"unveil"</span>);</code>
<h2>Demo</h2>
<p>The images were taken from the The Fox is Black <a href="http://www.thefoxisblack.com/category/the-desktop-wallpaper-project/">Desktop Wallpaper Project</a> - cool stuff!</p>
<p>If you're on a "normal" display, unveil will load the low resolution version (800x500). In case you're on a device with a retina display, the high resolution version (1280x800 in this case) will be loaded instead.</p>
<p>Scroll down to see it working.</p>
<ul>
<li><img src="img/loader.gif" data-src="img/anti-bullying-tom-froese-wallpaper-800x500.jpg" data-src-retina="img/anti-bullying-tom-froese-wallpaper-1280x800.jpg" /></li>
<li><img src="img/loader.gif" data-src="img/brock-davis-wallpaper-800x500.jpg" data-src-retina="img/brock-davis-wallpaper-1280x800.jpg" /></li>
<li><img src="img/loader.gif" data-src="img/dark-igloo-wallpaper-800x500.jpg" data-src-retina="img/dark-igloo-wallpaper-800x500.jpg" /></li>
<li><img src="img/loader.gif" data-src="img/dark-igloo-wallpaper-1-800x500.jpg" data-src-retina="img/dark-igloo-wallpaper-1-800x500.jpg" /></li>
<li><img src="img/loader.gif" data-src="img/iceland-smojr-wallpaper-800x500.jpg" data-src-retina="img/iceland-smjor-wallpaper-1280x800.jpg" /></li>
<li><img src="img/loader.gif" data-src="img/james-olstein-wallpaper-800x500.jpg" data-src-retina="img/james-olstein-wallpaper-1200x800.jpg" /></li>
<li><img src="img/loader.gif" data-src="img/johanna-basford-wallpaper-800x500.jpg" data-src-retina="img/johanna-basford-wallpaper-1280x800.jpg" /></li>
<li><img src="img/loader.gif" data-src="img/Jude_Landry_Wallpaper_800x500.jpg" data-src-retina="img/Jude_Landry_Wallpaper_1280x800.jpg" /></li>
<li><img src="img/loader.gif" data-src="img/julieta-felix-wallpaper-800x500.jpg" data-src-retina="img/julieta-felix-wallpaper-1280x800.jpg" /></li>
</ul>
<div class="big">
<div class="vertical"><img src="img/loader.gif" data-src="img/haik-avanian-wallpaper-800x500.jpg" data-src-retina="img/haik-avanian-wallpaper-1280x800.jpg" /></div>
<div class="horizontal"><img src="img/loader.gif" data-src="img/Timothy-J-Reynolds-wallpaper-800x500.jpg" data-src-retina="img/Timothy-J-Reynolds-wallpaper-1200x800.jpg" /></div>
</div>
<h2>Download</h2>
<p>Download the script from the project page on <a href="https://github.com/luis-almeida/unveil">GitHub</a>.</p>
<p>If you have any suggestion or bug to report please use github issues or get it touch with me on twitter - <a href="https://twitter.com/lmgalmeida">@lmgalmeida</a>.</p>
<h2>License</h2>
<p>Unveil is licensed under the <a href="http://opensource.org/licenses/MIT">MIT license</a>.</p>
<script>
// Twitter
!function(d,s,id){
var js,fjs=d.getElementsByTagName(s)[0];
if(!d.getElementById(id)){
js=d.createElement(s);
js.id=id;
js.src="//platform.twitter.com/widgets.js";
fjs.parentNode.insertBefore(js,fjs);
}
}(document,"script","twitter-wjs");
// Analytics
var _gaq=[['_setAccount','UA-30936310-1'],['_trackPageview']];
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
s.parentNode.insertBefore(g,s)}(document,'script'));
</script>
</body>
</html>