Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Timed image-change in layer

Status
Not open for further replies.

michelledebeer

Programmer
Oct 26, 2001
22
0
0
SE
I want to change an image in a layer every minute.

I have an idea of the codeflow:

FUNCTIONS:

var remember = 0;
var minutepicture = array('1.gif','2.gif' etc...);

timer()
{
//activate pick_picture() every 6000 ms
setTimeout('pick_picture()',6000);
}

function pick_picture()
{
if (remember == 60)
remember = 0;
if (remember != 0)
remember = remember+1;
print_picture(minute_picture[remember]);
}

print_picture(picture)
{
//print picture to the layer...
// This is the real problem.
// How do I replace the content of the layer?
name_of_layer.write('<img src='+picture+'>');
}



It has been a while since I worked with JS, so I don't know if this code is actually correct. Have been working mainly with PHP lately...

Any Thoughts?

// Michelle
 
Ok... an update...
Now I fixed everything but the writing to the layer...

Anyone know how to replace content in a layer?

// Michelle
 
Where you want to change the image,

Code:
function print_picture(picture) {
 with(document.layers['myLayer']) {
  document.open();
  document.write('<img src=&quot;'+picture+'&quot;>');
  document.close();
 }
}

Just make sure that the image is not larger than the window. If it is, the window will not resize unless you explicitly tell it to (remember, we're dealing with pre-Gecko Netscape here).
 
He michelledebeer,

Look on my homepage, scroll the lefthandside menu all the
way down and click on the &quot;Gorgeous Girls&quot; link (i know,
im a guy, i cant help myself ;-) Wait until the preloading
script is done. Then you get a perfect example of how to
do that in JavaScript. In my version the users can set the
time (in seconds) so that it changes that fast. And you
get to see the script in action!

It was originally written as a banner script but I
rewrote it to fit my needs (allota work actually!).

You can just rightmouse click on the page and choose
View Source, it's totally unprotected.

I hope this helps, BobbaFet

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com

&quot;<beer brand> is like making love in a cano...
it's <f-word + ing> close to water !!!&quot;
- Monty Python's Flying Circus, 1969/70
 
ow yeah, i forgot:

the parts you need to take a look at are:
function cycle() {}
function loadbanners() {}
<body onLoad=&quot;&quot;>

and last BUT NOT LEAST: <IMG border=&quot;0&quot; src=&quot;001.jpg&quot; name=&quot;banner1&quot; height=&quot;70%&quot;>

Greetz, BobbaFet

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com

&quot;<beer brand> is like making love in a cano...
it's <f-word + ing> close to water !!!&quot;
- Monty Python's Flying Circus, 1969/70
 
UNIMENT,
What is the correct way to write this for IE?

document.layers['myLayer']

This only works for Netscape...

// Michelle
 
IE and NS 6 don't support layers. Instead, you must use a DIV tag.
Code:
<div id=&quot;myLayer&quot;></div>
You access it like this for IE:
Code:
myDiv=document.all.myLayer
And for DOM 1:
Code:
myDiv=document.getElementById(&quot;myLayer&quot;)
Then, in order to edit the contents of
Code:
myLayer
, for NS 6 and IE, you use the
Code:
innerHTML
property. It's quite convenient and easy to use:
Code:
myDiv.innerHTML='<img src=&quot;&quot;>';



Here's the complete function:
Code:
var ns  = document.layers?1:0;
var ie  = document.all?1:0;
var dom = document.getElementById?1:0;

function print_picture(picture) {
 var tempLayer=
  ie?document.all['myLayer']:
  ns?document.layers['myLayer'].document:
  document.getElementById('myLayer');
 if (ns) {
  tempLayer.open();
  tempLayer.write('<img src=&quot;'+picture+'&quot;>');
  tempLayer.close();
 }
 else
  tempLayer.innerHTML='<img src=&quot;'+picture+'&quot;>';
}

And here's the HTML:
Code:
<layer name=&quot;myLayer&quot;>
<div id=&quot;myLayer&quot;>
</div>
</layer>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top