forked from jetmartin/responsive-lazy-loader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
190 lines (179 loc) · 9.18 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
<!DOCTYPE html>
<html lang="fr" xmlns:og="http://opengraphprotocol.org/schema/">
<head>
<base href="/" />
<title>[Responsive lazy loader]</title>
<meta charset="utf-8"/>
<meta http-equiv="CACHE-CONTROL" content="NO-CACHE"/>
<meta name="Description" content="" />
<meta name="Keywords" content="" />
<meta name="Author" content="@j_et_martin" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no"/>
<meta name="apple-mobile-web-app-title" content="">
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name="apple-mobile-web-app-status-bar-style" content="black"/>
<link rel="apple-touch-icon" href="touch-icon-iphone.png" />
<link rel="apple-touch-icon" sizes="72x72" href="touch-icon-ipad.png" />
<link rel="apple-touch-icon" sizes="114x114" href="touch-icon-iphone-retina.png" />
<link rel="apple-touch-icon" sizes="144x144" href="touch-icon-ipad-retina.png" />
<link rel="shortcut icon" href="" />
<link rel="icon" href="" />
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="/css/main.css" />
<script src="js/modernizr-2.6.2.min.js"></script>
</head>
<body>
<div id="main-container">
<h1>Responsive lazy loader</h1>
<section class="container">
<div class="row">
<div class="col-md-12">
<h2>Main frame</h2>
<p>Responsive lazy loader allows you lo load the most appropriate image renditions according to the current breakpoint and to the current display into the CSS grid-system.</p>
<p>It can be used as a simple lazy loader, simply as a responsive lazy loader (taking care of the breakpoint) or as an advanced lazy loader taking care of breakpoint and display.</p>
<h3>How it works</h3>
<p>The lazy loader recognizes the current display (size in a grid system for example) and breakpoint (mediaquery) and replaces a token in the image URL.</p>
<p>It works with any HTML/CSS structure/framework as bootstrap or foundation and any image provider as Flickr or CMS using image preset (rendition, styles, ...) as Adobe CQ or Drupal.</p>
<p>The plugin is only 3Ko (minified).</p>
<p><a href="demo.html" title="view he demo">View a demo</a></p>
<h2>How to use</h2>
<h3>HTML</h3>
<p>Replace your img tags by the following :</p>
<pre><img class="img-responsive" data-src="http://www.domain.tld/img-[[display]].jpg" src="js/pixel.gif" alt="image">
<noscript><img class="image-asset" src="http://www.domain.tld/img-defaults.jpg" alt="image"></noscript></pre>
<h3>CSS</h3>
<p>The image size must be at 100% for the image to be "responsive", it means that the image will be adjusted to the parent element. You must set up your breakpoint to never upscale an image and to load the image closest to the maximum display width.
<br />For example, if your site is 1200px on desktop you have to load an image as close as possible to 1200px but on a phone, if your max-width is 320 pixels, you have to load an image as close as possible to 320 but not too small.</p>
<p>For a nice display, you need to use a "loader" background for the images and/or outline.
<br />It could be something like :</p>
<pre>.img-responsive{
width:100%;
outline:#aaa;
background:#ccc url(../img/loader.gif) center center no-repeat;
}</pre>
<p>Add the noscript fallback :</p>
<pre><noscript><style type="text/css" media="all">img[data-src] { display: none; }</style></noscript></pre>
<p>Always use the "desktop" as default value because almost all modern device browsers support mediaqueries detections. This is not the case for old desktop browsers, such as old IE, so the current mediaquery will always be the "defaults" one. Even in an old browser, the display will be recognized and the appropriate image will load anyway.</p>
<h3>Tip</h3>
<p>The height auto is not displayed the same way on all the browsers.</p>
<p>To prevent the image height to change on an image load (text moving effect in some browsers), the image height has to be managed in CSS according to the site layout.</p>
<p>If all the images do not necessary have the same ratio (as 16/9 or 4/3), you can use the onImageShow callback function for custom actions.</p>
<h3>How to configure</h3>
<p>You can add arguments on the function call or override the defaults.</p>
<pre>$("img[data-src]").responsivelazyloader({
mediaQueries : { // The mediaqueries used by the lazyloder.
'phone' : "(max-width: 767px)",
'tablet' : "(min-width: 768px) and (max-width: 991px)",
'desktop' : "(min-width: 992px)"
},
displays : { // The displays to combine grid system & mediaqueries
'defaults' : {
'display' : {
'desktop' : 'b', //1024
'tablet' : 'z', //640
'phone' : 'm', //320
'defaults' : 'b' //1024
}
}
}
});</pre>
<p>Or</p>
<pre>// Owerrde defaults
$.fn.responsivelazyloader.defaults.mediaQueries = { // The mediaqueries used by the lazyloder.
'phone' : "(max-width: 767px)",
'tablet' : "(min-width: 768px) and (max-width: 991px)",
'desktop' : "(min-width: 992px)"
};
$.fn.responsivelazyloader.defaults.displays = { // The displays to combine grid system & mediaqueries
'defaults' : {
'display' : {
'desktop' : 'b', //1024
'tablet' : 'z', //640
'phone' : 'm', //320
'defaults' : 'b' //1024
}
}
};
$("img[data-src]").responsivelazyloader();</pre>
<p>An advance configuration using displays. The first valid display will be used.</p>
<p>The "parent" parameter is now optional. "gridClass" parameter will be use as "parent" if it is not specified.
<br />"parent" is a jQuery element declaration as ".myParentClass" or "section.myParentClass".
<br />"gridClass" is a class name as "myDisplayClass".</p>
<pre><section>
<article class="sidebar">{...}</article>
<aside class="sidebar">{...}</aside>
</section></pre>
<pre>
$.fn.responsivelazyloader.defaults.displays = { // The displays to combine grid system & mediaqueries
'articleWithSidebar' : {
'parent' : 'article.sidebar',
'gridClass' : 'sidebar',
'display' : {
'phone' : 'm', //320
'defaults' : 'z' //640
}
},
'sidebar' : {
'gridClass' : 'sidebar',
'display' : {
'defaults' : 'm' //320
}
},
'defaults' : {
'display' : {
'desktop' : 'b', //1024
'tablet' : 'z', //640
'phone' : 'm', //320
'defaults' : 'b' //1024
}
}
};
</pre>
<h3>AJAX</h3>
<p>The lazyloader can be used with AJAX.</p>
<pre>// Init lazyloader
$("img[data-src]").responsivelazyloader();
// Init lazyloder after ajax events.
$("body").on({ ajaxStop : function(){ $("img[data-src]").responsivelazyloader(); }});</pre>
<h3>Settings</h3>
<p>All available settings :</p>
<ul>
<li>distance = Int | distance of the image to the viewable browser screen before it gets loaded</li>
<li>token = string | The token replaced by the current display pattern.</li>
<li>force = Bool | Force loading without distance.</li>
<li>mediaQueries = Object | The mediaquery used by the lazy loader.</li>
<li>displays = Object | The display properties, match the grid class and the mediaqueries</li>
<li>onImageShow = function | Callback when an image has been lazy loaded.</li>
<li>onImageError = function | Callback when an image could not be lazy loaded.</li>
<li>onAllImagesLoad = function | Callback when all the images of the set are loaded.</li>
<li>Custom events :
<ul>
<li>responsiveImageLoaded -> Trigger on each image load. Custom var :
<br />- image : The currently loaded image.</li>
<li>onMediaqueryChange -> Trigger when mediaquery has change. Custom var :
<br />- CurrentMediaQuery : the current mediaquery key according to Settings.mediaQueries.
<br />- PreviousMediaQuery : The previous mediaquery key according to Settings.mediaQueries.</li>
</ul></li>
</ul>
<h3>Debug</h3>
<p>To help you setup the lazyloader, you can use the following code :</p>
<pre>$(window).on('responsiveImageLoaded', function(event){
$image = $(event.image[0]);
$image.next().remove();
$image.after(
"<p>Current mediaquerry : " + $image.attr("data-current-mediaq")
+ "<br />Current display : " + $image.attr("data-display") + "</p>"
);
});</pre>
<h2>More</h2>
<p>You can also use Responsive Lazy Loader on Drupal using our Drupal Module.</p>
<p>For more information, please contact me @j_et_martin.</p>
</div>
</div>
</section>
</div><!-- /main-container -->
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js" charset="utf-8"></script>
</body>
</html>