You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
These two `data-*` attributes are copied from the responsive placeholder to the response `img` element.nnot process images or who have image loading disabled. It is converted to the `alt` attribute of the `img element.
You can create one or several concurrent configurations of Imager within the same page. Its configuration options are
249
-
described below.
250
-
251
-
[Advanced JavaScript API documentation lies in the `docs/` folder](docs/js-api.md).
252
-
253
-
### `availableWidths`
254
-
255
-
This option is intended to reflect the available widths of each responsive image. These values will be used as replacements
256
-
for the `{width}` variable in `data-src` placeholders.
257
-
258
-
The following examples demonstrate the results of passing through different object types for the `availableWidths` option...
259
-
260
-
`Array`: the widths are represented as numeric values
261
-
262
-
```js
263
-
newImager({
264
-
availableWidths: [240, 320, 640]
265
-
});
266
-
```
267
-
268
-
`Object`: the widths associate a string value for their numeric counterpart
269
-
270
-
```js
271
-
newImager({
272
-
availableWidths: {
273
-
240:'small',
274
-
320:'medium',
275
-
640:'large'
276
-
}
277
-
});
278
-
```
279
-
280
-
`Function`: must return a value for the provided width argument
281
-
282
-
```js
283
-
// will return a double sized image width as a numeric value
284
-
newImager({
285
-
availableWidths:function (image) {
286
-
returnimage.clientWidth*2;
287
-
}
288
-
});
289
-
```
290
-
291
-
### `availablePixelRatios`
292
-
293
-
An Array which indicates what are the available pixel ratios available for your responsive images.
294
-
295
-
These values will be used as replacements for the `{pixel_ratio}` variable in `data-src` placeholders.
296
-
297
-
```js
298
-
newImager({ availablePixelRatios: [1, 2] });
299
-
```
300
-
301
-
**Default value**: `[1, 2]`
302
-
303
-
### `className`
304
-
305
-
A String which indicates what the `className` value will be added on the newly created responsive image.
306
-
307
-
```js
308
-
newImager({ className:'image-replace' });
309
-
```
310
-
311
-
**Default value**: `image-replace`
312
-
313
-
### `scrollDelay`
314
-
315
-
An Integer value (in milliseconds) to indicate when Imager will check if a scroll has ended. If a scroll has stopped after this delay and the `lazyload` option is `true`, Imager will update the `src` attribute of the relevant images.
316
-
317
-
**Default value**: `250`
318
-
319
-
```js
320
-
newImager({ scrollDelay:250 });
321
-
```
322
-
323
-
**Notice**: set the `scrollDelay` value to `0` at your own risk; unless you know what you're doing, setting the value to zero will make the user experience totally janky! (and that would be an odd thing to do as you have chosen to use Imager to improve the user experience)
324
-
325
-
### `onResize`
326
-
327
-
A Boolean value. If set to `true`, Imager will update the `src` attribute of the relevant images.
328
-
329
-
**Default value**: `true`
330
-
331
-
```js
332
-
newImager({ onResize:true });
333
-
```
180
+
Browse Imager public APIs and options – versioned alongside the source code of the project:
334
181
335
-
### `lazyload`
336
-
337
-
An *experimental* Boolean value. If set to `true`, Imager will update the `src` attribute only of visible (and nearly visible) images.
338
-
339
-
**Default value**: `false`
340
-
341
-
```js
342
-
newImager({ lazyload:true });
343
-
```
344
-
345
-
### `lazyloadOffset`
346
-
347
-
A `Number` of extra pixels below the fold taken in account by the lazyloading mechanism.
348
-
349
-
**Default value**: `0`
350
-
351
-
```js
352
-
newImager({ lazyload:true, lazyloadOffset:300 });
353
-
```
354
-
355
-
### `onImagesReplaced`
356
-
357
-
A callback `Function`. Runs after Imager updates the `src` attribute of all relevant images.
358
-
359
-
Its first and unique argument is an `Array` of `HTMLImageElement`, the ones processed by Imager.
360
-
361
-
```js
362
-
newImager({
363
-
onImagesReplaced:function(images) {
364
-
console.log('the src of all relevant images has been updated');
365
-
}
366
-
});
367
-
```
368
-
369
-
## JavaScript API
370
-
371
-
### `.ready(fn)`
372
-
373
-
Executes a function when Imager is ready to work.
374
-
375
-
```js
376
-
newImager({ ... }).ready(function(){
377
-
console.log('Placeholders divs have been replaced');
378
-
});
379
-
```
380
-
381
-
### `.add(elements | selector)`
382
-
383
-
Add new elements to the existing pool of responsive images.
384
-
385
-
```js
386
-
var imgr =newImager('.delayed-image-load');
387
-
388
-
imgr.add('.new-delayed-image-load-selector');
389
-
imgr.add(newElements);
390
-
imgr.add(); // reuses the constructor selector ('.delayed-image-load')
391
-
```
182
+
-[HTML options](docs/html-api.md)
183
+
-[JavaScript options](docs/js-options.md)
184
+
-[JavaScript API](docs/js-api.md)
392
185
393
186
# Demos
394
187
@@ -398,8 +191,10 @@ Additional and fully working examples lie in the [`demos` folder](demos/).
398
191
# They are using it
399
192
400
193
-[BBC News](http://m.bbc.co.uk/news)
194
+
-[BBC Sport](http://m.bbc.co.uk/sport)
401
195
-[The Guardian](http://www.theguardian.com/)
402
196
-[`x-imager` Web Component](https://github.com/addyosmani/x-imager)
@@ -415,6 +210,7 @@ Much of this work can be repurposed to work with a more standards-based approach
415
210
416
211
For the purposes of maintaining a distinguishment between the ImageEnhancer concept built by BBC News and this project, we're calling it **Imager.js**
417
212
213
+
**[Read more on BBC Responsive News blog](http://responsivenews.co.uk/post/58244240772/imager-js)**.
418
214
419
215
# Credits
420
216
@@ -426,7 +222,7 @@ For the purposes of maintaining a distinguishment between the ImageEnhancer conc
426
222
427
223
# Licence
428
224
429
-
> Copyright 2014 British Broadcasting Corporation
225
+
> Copyright 2015 British Broadcasting Corporation
430
226
>
431
227
> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
These two `data-*` attributes are copied from the responsive placeholder to the response `img` element.nnot process images or who have image loading disabled. It is converted to the `alt` attribute of the `img element.
0 commit comments