我真的不明白我的这个预加载片段有什么问题,loadWrapper 像 if 语句不起作用一样消失并不重要。希望任何人都可以发现问题:
//html
<script type='text/javascript'>$(document).ready(function(){preloadImages()});</script>
//js
function preloadImages()
{
var xmlDoc = loadXMLDoc("http://www.wdagdesign.com/ice2/menu.xml");
var y = xmlDoc.getElementsByTagName("title");
var imgCount = y.length;
for(var i=0; i<imgCount;i++)
{
var imgObj = new Image();
var $pic = xmlDoc.getElementsByTagName("pic")[i].childNodes[0].nodeValue;
imgObj.src = $pic;
imgObj.onLoad = imagesLoaded($pic);
}
}
var $imageCount = 0;
function itemsLength()
{
var xmlDoc = loadXMLDoc("http://www.wdagdesign.com/ice2/menu.xml");
var y = xmlDoc.getElementsByTagName("title");
return y.length;
}
function imagesLoaded($pic)
{
$imageCount += 1;
if($imageCount != itemsLength())
{
return;
}else{
createMenu();
var $loadingWrapper = document.getElementById('loadingWrapper');
var $loading= document.getElementById('loading');
TweenMax.to($loadingWrapper,0,{css:{display:'none'}});
TweenMax.to($loading,0,{css:{display:'none'}});
$imageCount = 0;
}
}
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else
{
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET",dname,false);
xhttp.setRequestHeader("Cache-Control", "no-cache");
xhttp.setRequestHeader("Pragma", "no-cache");
xhttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
xhttp.send();
return xhttp.responseXML;
}
希望有人可以帮我解决这个问题。问候。