Skip to content

Instantly share code, notes, and snippets.

@JMPerez
Created March 5, 2017 18:57
Show Gist options
  • Save JMPerez/e8496fca2063a7cb811ded3d1f6a92e9 to your computer and use it in GitHub Desktop.
Save JMPerez/e8496fca2063a7cb811ded3d1f6a92e9 to your computer and use it in GitHub Desktop.
// draw the data-uri image on the canvas
function a(e) {
if (e.getAttribute("data-src")) {
var t = new Image;
t.src = e.getAttribute("data-src");
var i = e.getAttribute("width")
, n = e.getAttribute("height")
, o = e.getContext("2d");
t.addEventListener("load", function() {
o.drawImage(t, 0, 0, i, n)
}, false)
}
}
// go through all canvas on the page with a data-src
function r() {
var e = document.querySelectorAll("canvas[data-src]");
d.insertionQ("canvas[data-src]").every(function(e) {
a(e)
}),
[].forEach.call(e, a)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment