gerble1000
07-01-2012, 01:33 PM
i have a simple image swap code here
<SCRIPT language="JavaScript">
function movepic(img_name,img_src)
{
objImage = new Image();
objImage.onLoad=imagesLoaded();
objImage.src=img_src;
function imagesLoaded()
{
document[img_name].src=img_src;
}
}
</SCRIPT>
that code works lovely.
now i want to display a loading.gif while its loading.
here is my new code
<SCRIPT language="JavaScript">
function movepic(img_name,img_src)
{
document.getElementById("loading").style.display="block";
objImage = new Image();
objImage.onLoad=imagesLoaded();
objImage.src=img_src;
function imagesLoaded()
{
document[img_name].src=img_src;
document.getElementById("loading").style.display="none";
}
}
</SCRIPT>
either it does not set the loading to visible or it does and then instantly makes it not visible but either way its not working.
the code below works fine document.getElementById("loading").style.display="block";
so please tell me what i am doing wrong.
the code gets executed from an onclick div inside a table td
<SCRIPT language="JavaScript">
function movepic(img_name,img_src)
{
objImage = new Image();
objImage.onLoad=imagesLoaded();
objImage.src=img_src;
function imagesLoaded()
{
document[img_name].src=img_src;
}
}
</SCRIPT>
that code works lovely.
now i want to display a loading.gif while its loading.
here is my new code
<SCRIPT language="JavaScript">
function movepic(img_name,img_src)
{
document.getElementById("loading").style.display="block";
objImage = new Image();
objImage.onLoad=imagesLoaded();
objImage.src=img_src;
function imagesLoaded()
{
document[img_name].src=img_src;
document.getElementById("loading").style.display="none";
}
}
</SCRIPT>
either it does not set the loading to visible or it does and then instantly makes it not visible but either way its not working.
the code below works fine document.getElementById("loading").style.display="block";
so please tell me what i am doing wrong.
the code gets executed from an onclick div inside a table td