function checkImages() {
// Create an array and push all add all images in the viewport to the array.
var imgs = [];
Y.all('img[data-src]:not([src])').each(function(img) {
if (img.inRegion(Y.DOM.viewportRegion())) {
imgs.push(img);
}
});
// Load the eligible images and remove the data-load attributes from them.
for (var i = 0; i < imgs.length; i++) {
ImageLoader.load(imgs[i].removeAttribute('data-load'));
}
}
Y.use('node', function() {
Y.on('domready', function() {
// Call the function on domready and on scroll.
checkImages();
Y.on('scroll', checkImages);
});
});
img:not([src]) {
opacity: 0;
}
img {
opacity: 1;
-moz-transition: opacity: 0.2s ease;
-webkit-transition: opacity 0.2s ease;
transition: opacity 0.2s ease;
}