Skip to content

Instantly share code, notes, and snippets.

@abstrctn
Created April 22, 2014 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abstrctn/11188031 to your computer and use it in GitHub Desktop.
Save abstrctn/11188031 to your computer and use it in GitHub Desktop.
var s=document.createElement('script');
s.setAttribute('src','http://code.jquery.com/jquery.js');
document.getElementsByTagName('body')[0].appendChild(s);
setTimeout(function() {
svg = $("svg[width=690]")[0];
var svgNS = svg.namespaceURI;
var bg = document.createElementNS(svgNS, 'pattern');
bg.setAttribute('id', 'derek');
bg.setAttribute('x', 10);
bg.setAttribute('y', 10);
bg.setAttribute('patternUnits', 'userSpaceOnUse');
bg.setAttribute('height', 19);
bg.setAttribute('width', 19);
var image = document.createElementNS("http://www.w3.org/2000/svg", "image");
image.setAttribute('x', 0);
image.setAttribute('y', 0);
image.setAttribute('width', 19);
image.setAttribute('height', 19);
image.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href", "http://graphics8.nytimes.com/packages/images/nytint/projects/upshot/derek-willis.jpg");
bg.appendChild(image);
var defs = svg.insertBefore( document.createElementNS(svgNS,'defs'), svg.firstChild);
defs.appendChild(bg);
var circles = $(svg).find("circle");
for (i=0; i<circles.length; i++) {
var circle = circles[i];
circle.setAttribute('style', '');
circle.setAttribute('fill', "url(#derek)");
}
}, 500);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment