Multiple methods to load the image once it is displayed
- 2020-03-30 01:46:21
- OfStack
Method one:
Method 2:
Method 3:
<script type= " text/javascript " >
var obj = new Image();
obj.src = " yourpicurl.jpg " ;
obj.onload = function() { //This place can be repeated to write, if the error, change to the outside
document.getElementById( " mypic " ).innnerHTML = " <img src=' " +this.src+ "' /> " ;
}
</script>
<div id= " mypic " >onloading ... </div>
Method 2:
<script type= " text/javascript " >
var obj = new Image();
obj.src = " yourpicurl.jpg " ;
obj.onreadystatechange = function() {
if ( this.readyState == " complete " ) { //This place can be repeated to write, if the error, change to the outside
document.getElementById( " mypic " ).innnerHTML = " <img src=' " +this.src+ "' /> " ;
}
}
</script>
<div id= " mypic " >onloading ... </div>
Method 3:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> Headless document </title>
</head>
<script language="javascript" src="/js/jquery-1.4.4.js" type="text/javascript">
</script>
<script language="javascript" type="text/javascript">
<!--//var total;var curt = 0;$(document).ready(function()
{
total = $("#content img").length;
$("#content img").each(function(){ var image = new Image();
image.src = $(this).attr('src');
if (image.complete){
imageLoaded();
}
else{
image.onload = imageLoaded;
}
});
});
function imageLoaded(){
curt+=1;
if(curt==total){
$("#content").show();
}}//-->
</script>
</head>
<body>
<div id="content" style="display:none;" >
<img src="" />
<img src="" />
<img src="" />
</div>
</body>
</html>