PDA

View Full Version : flash Image on load


glenmac
08-30-2004, 09:05 AM
I was playing with a script I found and adapted it to load an image on page loading then disapear. I hope it's usefull.
<head>

<script>
var tmp = 0;
var num = 0;
var img = null;
var timer = null;

function expand(it) {
//tmp = it.width; // save original size
num = 0;
img = it;
timer = setTimeout("exp()",10); // 10ms steps
}

function exp() {
//img.align = "right";
img.width = img.width * 1.1; // 10% each time
img.height = img.height * 1.1; // 10% each time
//
num++
if (num < 9) // 9 steps then stop
{timer = setTimeout("exp()",10);}
}

function shrink(it) {
clearTimeout(timer); // stop if active
it.style.display ="none"//hidePic
//it.width = "0px";//you can set width and height of shrink
//it.height = "0px";//or use tmp to return to original

}
</script>
</head>
<body onload ="expand(test); setTimeout('shrink(test)',2000)"><div align = "center"><img src = "yourImage.jpg" id ="test" ></div>
test text
</body>

jamescover
08-30-2004, 09:44 AM
load an image on page loading then disapear.

That's a lot of code for what you've described:


<div style="position:absolute;top:25;left:45;" id="loading"><img src="images/loadingImage.gif" width="72" height="31" border="0" alt="loadingImage.gif" /></div>


<img src="images/loadedImage.jpg" onload="document.getElementById('loading').style.visibility='hidden';" width="250" height="250" border="0" alt="loadedImage.jpg" />


-james

glenmac
08-30-2004, 02:11 PM
True but have you tested your code, it doesn't work for me? As well if it did the space taken by the image is still used using the "visibility" attribute. "Display:none" doesn't take any space on the page.

jamescover
08-30-2004, 06:52 PM
True but have you tested your code, it doesn't work for me?

Yes, I have/had...it works in IE6.0 and Firefox 0.9.3


Maybe, try it here:

http://www.ekigroup.com/dbdemo/imgLoad.html

You can add NS7.2 to the above list

-james

glenmac
09-03-2004, 06:21 PM
I appologize for my misunderstanding, when I tried your code on my own machine the image loaded so quickly that I never saw the loading image. In my code you always see the loading image. I'm thinking we are talking apples and oranges here but thanks for your input.

jamescover
09-04-2004, 01:48 AM
I appologize for my misunderstanding, when I tried your code on my own machine the image loaded so quickly that I never saw the loading image. In my code you always see the loading image. I'm thinking we are talking apples and oranges here but thanks for your input.

No, no. No reason to apologize. Hope you didn't think I was knocking your code--just offering an alternative...learning all the while... :thumbsup:


cheers,


-james