Unveil.js

Lightway version of Lazy Load with support for serving
high-resolution images to devices with retina displays

Usage

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.

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.

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.

<img src="bg.png" data-src="img1.jpg" />
<img src="bg.png" data-src="img2.jpg" data-src-retina="img2-retina.jpg" />

If you care about users without javascript enabled, you can include the original image inside a <noscript> tag:

<noscript>
  <img src="img1.jpg" />
</noscript>


Run the script on document ready:

$(document).ready(function() {
  $("img").unveil();
});

Options

By default, images are only loaded and "unveiled" when the user scrolls to them and they became visible on the screen.

If you want your images to load earlier than that, lets say 200px before they appear on the screen, you just have to:

$("img").unveil(200);

Trigger

You can still trigger image loading whenever you need.

All you have to do is select the images you want to "unveil" and trigger the event:

$("img").trigger("unveil");

Demo

The images were taken from the The Fox is Black Desktop Wallpaper Project - cool stuff!

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.

Scroll down to see it working.

License

Unveil is licensed under the MIT license.