»
EnglishFrenchVietnamese

Print - xImgAsyncWait - JavaScriptBank.com

Full version: jsB@nk » Misc » xImgAsyncWait
URL: https://www.javascriptbank.com/sliders-ximgasyncwait.html

xImgAsyncWait © JavaScriptBank.comxImgAsyncWait asynchronously waits (and monitors the status) of newly created or static images. Can be called before or after window.onload, or in the HTML following the last IMG element. During monitoring of image load status, your status function will be called at each iteration. After all images successfully load, your app initialization function is called. If any image fails to load, your error function is called. You can provide error and abort images for those that fail to load.

Full version: jsB@nk » Misc » xImgAsyncWait
URL: https://www.javascriptbank.com/sliders-ximgasyncwait.html



CSS
<link rel="stylesheet" type="text/css" href="v3.css"><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


JavaScript
<script type="text/javascript">window.onload = function(){    if (window.winOnLoad) window.winOnLoad();}</script><script type="text/javascript" src="x_img.js"></script><script type="text/javascript">/*  There are three different ways to use xImgAsyncWait().  1. Create new images and call it before the onload event.  2. Create new images and call it after the onload event.  3. Call it in the HTML immediately after the last IMG element.  In 1 and 2 it will monitor the status of the newly created images  because you pass it an array of the new img objects.  In 3 it will monitor the status of all static images  because you do not pass it an array.*/var aImgs = new Array();/***// If new images are created before the window.onload event:newImg('../../images/grn_bnr1.jpg');newImg('../../images/cbe.gif');newImg('../../images/mars.jpg');newImg('../../images/news.gif');newImg('../../images/search.gif');newImg('../../images/x.gif');newImg('../../images/xbanner.gif');newImg('../../images/noExist1.jpg');newImg('../../images/noExist2.jpg');log('', true);xImgAsyncWait(imgLoadStatus, appInitialize, appImgError, 'noExist1.jpg', 'noExist2.jpg', aImgs);***/function winOnLoad(){  // A splash page could be positioned and displayed here.  // If new images are created after the window.onload event  newImg('../image/logojs.gif');  newImg('../image/logojs.gif');  newImg('../image/logojs.gif');  newImg('../image/logojs.gif');  newImg('../image/logojs.gif');  newImg('../image/logojs.gif');  newImg('../image/logojs.gif');  newImg('../image/logojs.gif');  newImg('../image/logojs.gif');  log('', true);  xImgAsyncWait(imgLoadStatus, appInitialize, appImgError, 'noExist1.jpg', 'noExist2.jpg', aImgs);  // At this point our code continues to run but  // we're still waiting for images to load.  // Don't do anything here relating to images,  // do it in appInitialize().}// After all images have loaded successfully// then this function will be called:function appInitialize(){  // The splash page (if any) would be removed here.  // Finish application initializations,  // for example adding rollover event listeners.}// If any image was not loaded due to an error or an abort// then this function will be called instead of appInitialize:function appImgError(n, c, e, a){  var s = '\nFinal Image Status:' +          '\n total=' + n +          '\n loaded=' + c +          '\n errors=' + e +          '\n aborts=' + a;  log(s);}// This function is called at each iteration of image status monitoring:function imgLoadStatus(n, c, e, a){  var s = '\nImage Status:' +          '\n total=' + n +          '\n loaded=' + c +          '\n errors=' + e +          '\n aborts=' + a;  log(s);}// Utility functions for this demofunction newImg(sUrl){  var i = aImgs.length;  aImgs[i] = new Image();  aImgs[i].src = sUrl;}function log(s, bOverwrite){  var log = document.getElementById('debugLog');  if (log) {    if (bOverwrite) log.value = s;    else log.value += s;  }}</script><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<form><textarea id="debugLog" rows="24" cols="30"></textarea></form><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


Files
http://javascriptbank.com/javascript/misc/Sliders/v3.csshttp://javascriptbank.com/javascript/misc/Sliders/x_img.js