Skip to content

Instantly share code, notes, and snippets.

@sofish
Created November 1, 2011 10:32
Show Gist options
  • Save sofish/1330275 to your computer and use it in GitHub Desktop.
Save sofish/1330275 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8" />
<title>hihi</title>
</head>
<body>
<img id="thepic" src="javascript:''" />
<script type="text/javascript">
var preloadImg = function(url){
var img = new Image();
img.src = url;
if(img.complete){
alert('complete')
document.getElementById('thepic').src = url;
retrun;
}
img.onload = function(){
alert('onload')
document.getElementById('thepic').src = url;
};
};
preloadImg('http://sofish.de/mypics/alipay_logo.png');
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment