Skip to content

Instantly share code, notes, and snippets.

@chrisyip
Forked from disinfeqt/twitter_offscreen_preload.html
Created August 19, 2011 05:03
Show Gist options
  • Save chrisyip/1156086 to your computer and use it in GitHub Desktop.
Save chrisyip/1156086 to your computer and use it in GitHub Desktop.
window.onload = function(){
var doc = document
, img = doc.createElement('img')
, div = doc.createElement('div')
, body = doc.getElementsByTagName('body')[0];
img.className = 'preload';
img.style.cssText = ';position:absolute;top:-999em;left:-999em;width:0;height:0;visibility:hidden;';
// ajax loaded or predefined img list
var arr = imgList
, str
, tmp;
div.id = 'preload-wrapper';
while(src = arr.pop()){
tmp = img.cloneNode(!1);
tmp.src = src;
div.appendChild(tmp);
}
body.appendChild(div);
// remove div when all loaded
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment