Skip to content

Instantly share code, notes, and snippets.

@jonathansampson
Created October 17, 2014 00:05
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 jonathansampson/cfdf584c6cc7927da366 to your computer and use it in GitHub Desktop.
Save jonathansampson/cfdf584c6cc7927da366 to your computer and use it in GitHub Desktop.
Alternative implementation for http://apps.washingtonpost.com/g/page/politics/the-scale-of-american-ebola-infections/1381/?template=iframe which will avoid Stack size limitations in some browsers
<style>
#people {
margin-top: 20px;
}
#people img {
width: 100%;
display: block;
}
</style>
<div id="people"></div>
<script>
(function () { // Online Demo: http://jsfiddle.net/soy6d7pt/1/
"use strict";
var group = 0, groups = 14487, imageElement,
fragment = document.createDocumentFragment(),
container = document.getElementById( "people" ),
affected = Math.floor( Math.random() * groups ),
baseURL = "http://www.washingtonpost.com/blogs/the-fix/files/2014/10/";
for ( ; group < groups; group++ ) {
imageElement = document.createElement("img");
fragment.appendChild( imageElement );
if ( group === affected ) {
imageElement.src = baseURL + "people_inf.png";
continue;
}
imageElement.src = baseURL + "people_uninf.png";
}
container.appendChild( fragment );
}());
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment