Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Selectively Serving Images Using HTML5 “data-” attribute & Match Media for Responsive Site Re: Selectively Serving Images Using HTML5 “data-” attribute & Match Media for Responsive Site

#116690
robhawk
Member

Sorry I tried with it below the line starting lazy as well.

like so but still visible in IE…

/images enhancement
if (window.matchMedia(“(min-width: 46.875em)”).matches) {
//load in the images

var lazy = Utils.q(‘[data-src]’);
for (var i = 0; i < lazy.length; i++) {
var source = lazy
.getAttribute(‘data-src’);
//create the image
var img = new Image();
img.src = source;
//insert it inside of the link
lazy
.insertBefore(img, lazy.firstChild);
img.removeAttribute(‘height’);
img.removeAttribute(‘width’);
};