Skip to content

Commit 1b57c83

Browse files
author
aFarkas
committed
0.9.0-RC2
1 parent 86dc27f commit 1b57c83

File tree

4 files changed

+26
-17
lines changed

4 files changed

+26
-17
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@
4040
1. **Works without any configuration or JS callbacks in any web enviroment**: The script works as an universal, self-initializing, self-configuring and self-destroying component and detects any changes to the visibility of any current and future image/iframe elements automatically no matter whether it becomes visible through a user scroll, a CSS animation triggered through ``:hover`` or through any kind of JS behavior (carousel, slider, infinite scroll, isotope/filtering/sorting, AJAX, SPAs...). Also works automatically in conjunction with any kind of JS-/CSS-/Frontend-Framework (jQuery mobile, Bootstrap, Backbone, Angular, React, ember).
4141
2. **Future-proof**: It directly includes standard responsive image support (``picture`` and ``srcset``)
4242
3. **Separation of concerns**: For responsive image support it adds an automatic ``sizes`` calculation as also alias names for media queries feature. There is also no JS change needed if you add a scrollable container with CSS (overflow: auto) or create a mega menu containing images.
43-
4. **Performance**: It's based on high efficient and best practice code (runtime **and** memory) to work jank-free at 60fps.
44-
5. **Extendable**: It provides JS and CSS hooks to extend lazySizes with any kind of lazy loading or effects (see also the [available plugins/snippets](#plugins)).
43+
4. **Performance**: It's based on high efficient and best practice code (runtime **and** memory) to work jank-free at 60fps. Can be used with thousands of images/iframes on CSS and JS heavy pages/webapps.
44+
5. **Extendable**: It provides JS and CSS hooks to extend lazySizes with any kind of lazy loading, lazy instantiation, inview callbacks or effects (see also the [available plugins/snippets](#plugins)).
4545
6. **Intelligent prefetch**: lazySizes prefetches near the view assets, only while the browser network is idling. (see also ``expand`` option)
46-
7. **Lightweight, but mature solution**: lazySizes has the right balance between lightweight and a reliable and fast solution
46+
7. **Lightweight, but mature solution**: lazySizes has the right balance between a lightweight and a reliable and fast solution
4747

4848
##[Demo with code examples](http://afarkas.github.io/lazysizes/#examples)
4949
Can be seen [here](http://afarkas.github.io/lazysizes/#examples).
@@ -73,7 +73,7 @@ Add the ``class`` ``lazyload`` to all ``img`` and ``iframe`` elements, which sho
7373
responsive-image3.jpg 900w" class="lazyload" />
7474
```
7575

76-
**Important: How ``sizes`` is calculated**: The automatic sizes calculation takes the width of the image. If it is below ``50`` (can be configured through the ``minSize`` option), lazySizes traverses up the DOM tree until it finds a parent which is over ``50`` and uses this number. Often the following general CSS rule might help: ``img[data-sizes="auto"] { display: block; }``.
76+
**Important: How ``sizes`` is calculated**: The automatic sizes calculation takes the width of the image. If it is below ``50`` (can be configured through the ``minSize`` option), lazySizes traverses up the DOM tree until it finds a parent which is over ``50`` and uses this number. Often the following general CSS rule might help: ``img[data-sizes="auto"] { display: block; }``. (see also [specifying image/iframe dimensions](#specify-dimensions)
7777

7878
##Recommended markup patterns
7979
For some image bots (search engines and social networks), legacy browsers (IE8) or JS disabled browsers, it is important to serve a usable ``src`` attribute:
@@ -182,7 +182,6 @@ Here the list of options:
182182
* ``lazySizesConfig.srcset`` (default: ``"data-srcset"``): The attribute, which should be transformed to ``srcset``.
183183
* ``lazySizesConfig.sizesAttr`` (default: ``"data-sizes"``): The attribute, which should be transformed to ``sizes``. Makes almost only sense with the value ``"auto"``. Otherwise the ``sizes`` attribute should be used directly.
184184
* ``lazySizesConfig.customMedia`` (default: ``{}``): The ``customMedia`` option object is an alias map for different media queries. It can be used to separate your specific media queries implementation for the ``source[media]`` attribute by creating labeled media queries. (See also the [custommedia extension](plugins/custommedia)).
185-
* ``lazySizesConfig.init`` (default: ``true``): By default lazySizes initializes itself as soon as possible, to load inview assets as soon as possible. In the unlikely case you need to setup/configure something with a later script you can set this option to ``false`` and call ``lazySizes.init();`` later explicitly.
186185
```html
187186
<script>
188187
window.lazySizesConfig = window.lazySizesConfig || {};
@@ -213,6 +212,7 @@ window.lazySizesConfig.customMedia = {
213212
alt="image with artdirection" />
214213
</picture>
215214
```
215+
* ``lazySizesConfig.init`` (default: ``true``): By default lazySizes initializes itself as soon as possible, to load inview assets as soon as possible. In the unlikely case you need to setup/configure something with a later script you can set this option to ``false`` and call ``lazySizes.init();`` later explicitly.
216216

217217
####JS API - events
218218
**lazysizes** provides two events to modify or extend the behavior of **lazysizes**.
@@ -289,7 +289,7 @@ For CSS transition/animations or progress bars / spinners use the ``addClasses``
289289

290290
<script>
291291
window.lazySizesConfig = {
292-
//,expand: 80 //default is 150
292+
//,expand: 80 //default is 120
293293
};
294294
</script>
295295

@@ -425,7 +425,7 @@ Due to the fact, that it is designed to be invoked with a high frequency and the
425425
class="lazyload" />
426426
```
427427

428-
##Tip: Specifying image dimensions (minimizing reflows and avoiding page jumps)
428+
##<a name="specify-dimensions"></a>Tip: Specifying image dimensions (minimizing reflows and avoiding page jumps)
429429
To minimize reflows, content jumping or unpredictable behavior with some other JS widgets (isotope, masonry, some sliders/carousels...) the width **and** the height of an image should be calculable by the browser before the image source itself is loaded. For "static" images this can done using either CSS or using the content attributes:
430430

431431
```html

plugins/optimumx/ls.optimumx.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
if(typeof config.getOptimumX != 'function'){
5656
config.getOptimumX = function(/*element*/){
57-
var dpr = window.devicePixelRatio;
57+
var dpr = window.devicePixelRatio || 1;
5858
if(dpr > 2.4){
5959
dpr *= 0.63; // returns 1.9 for 3
6060
} else if(dpr > 1.9){

plugins/optimumx/ls.optimumx.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/functional-tests-plugins.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ $.extend(window.lazyTests, {
269269
riasReinit: ['lazysizes rias can be re-initialized', function(assert){
270270
var done = assert.async();
271271

272-
this.promise.always(function($){
272+
this.promise.always(function($, frameWindow){
273273
var placeholderSrc, $image;
274274
var initTest = function(){
275275
var success = [
@@ -320,6 +320,11 @@ $.extend(window.lazyTests, {
320320
var run = function(){
321321
if(test.length){
322322
placeholderSrc = test.shift();
323+
324+
if(!window.devicePixelRatio){
325+
$image.removeAttr('src');
326+
}
327+
323328
$image
324329
.attr('data-src', placeholderSrc[0])
325330
.addClass('lazyload')
@@ -328,23 +333,27 @@ $.extend(window.lazyTests, {
328333
done();
329334
}
330335
};
331-
332-
333-
$image = $('<img data-sizes="auto" style="width: 90%;" data-widths="[1, 500, 1200]" class="lazyload" />')
334-
.appendTo('body')
335-
;
336-
337-
run();
336+
$image = $('<img data-sizes="auto" style="width: 90%;" data-widths="[1, 500, 1200]" class="lazyload" />');
338337

339338
$image.on('lazybeforeunveil', function(e){
340339
setTimeout(function(){
340+
console.log('jo')
341341
placeholderSrc[1]();
342342
run();
343343
}, 9);
344344
});
345+
346+
$image.appendTo('body');
347+
348+
run();
345349
});
346350
}],
347351
optimumxReinit: ['lazysizes optimumx can be re-initialized', function(assert){
352+
353+
if(!window.devicePixelRatio){
354+
assert.ok(true);
355+
return;
356+
}
348357
var done = assert.async();
349358

350359
this.promise.always(function($){

0 commit comments

Comments
 (0)