gavmck / resize

Responsive image resizing via PHP, GD, Javascript
74 stars 25 forks source link

Why not use SRC and DATA-SRC in the IMG tag? #3

Closed ollie007 closed 9 years ago

ollie007 commented 9 years ago

Why not use SRC and DATA-SRC in the IMG tag?

is it easy to change it?

gavmck commented 9 years ago

If I remember rightly, it was to make loading states easier. Should just be a coupe of tweaks to the loadImage method in the js.

loadImage: function(image) {
      var el, img,
        _this = this;
      el = $("[data-src='" + image.og_src + "']");
      img = $("<img />");
      img.attr("src", image.src).attr("alt", el.attr("data-alt")).attr('data-src',image.og_src).attr('data-alt', el.attr("data-alt"));
      img.load(function() {
        el.replaceWith(img);
        img.addClass('img-loaded');
      });
    }

Something like that would do it. Could be more efficient, but it'll work I think (Not tested)