Nice floating Image Javascript code in header.html but unable to disappear

Nice floating Image Javascript code in header.html but unable to disappear

by Joanna Tsai -
Number of replies: 3

I have found one cool javascript code which can be embedded in header.html to let pics drop from the top and down to the bottom, nevertheless, the pics will go back to the top but not disappear, huh, it is a little disppointed, who can help to modify it, many thanks.

The belowing is added in the <body></body>

<body onload=doplay()>

#Layer0 {
 Z-INDEX: 10; LEFT: -50px; WIDTH: 60px; POSITION: absolute; TOP: -50px; HEIGHT: 60px
}
#Layer1 {
 Z-INDEX: 20; RIGHT: -100px; WIDTH: 60px; POSITION: absolute; TOP: -100px; HEIGHT: 60px
}
#Layer2 {
 Z-INDEX: 30; RIGHT: -150px; WIDTH: 60px; POSITION: absolute; TOP: -120px; HEIGHT: 60px
}
#Layer3 {
 Z-INDEX: 40; LEFT: -200px; WIDTH: 60px; POSITION: absolute; TOP: -150px; HEIGHT: 60px
}

BODY {
 FONT-SIZE: 9pt; WORD-SPACING: normal; LINE-HEIGHT: 13pt
}
P {
 FONT-SIZE: 9pt; WORD-SPACING: normal; LINE-HEIGHT: 13pt
}
TD {
 FONT-SIZE: 9pt; WORD-SPACING: normal; LINE-HEIGHT: 13pt
}
</STYLE>

<SCRIPT language=JavaScript>
xfirst = new Array(80,150,220,310,400,590,680); //the start position of x
yfirst = new Array(0,180,70,10,50,30,140);  //the start position of y
xcoor = new Array(80,150,220,310,400,590,680); 
ycoor = new Array(0,180,70,10,50,30,140);
xdirec= new Array(1,-1,-1,1); //the start direction -1 is to left and 1 is to right

var ns = navigator.appName == "Netscape";
  
function doplay()
{
    var x,y,i,j,w,h;
 w = window.screen.width - 100;
// w = document.body.clientWidth - 100;
 h = window.screen.height - 100;
// h = document.body.clientHeight - 50;
    for(j=0;j<4;j++){
     i=Math.random();      

     if (i > 0.95) xdirec[j] = 0 - xdirec[j]; 
     x=Math.floor(10*Math.random());
     y=Math.floor(5*Math.random()); 
     if ( xdirec[j] == 1 ) xcoor[j] = xcoor[j] + x;
     else xcoor[j] = xcoor[j] - x;
     ycoor[j] = ycoor[j] + y;    
     if ( xcoor[j] >= w ) {xcoor[j]=w;xdirec[j]=-1;}
     if ( xcoor[j] <= 0 ) {xcoor[j]=0;xdirec[j]=1;}
     if ( ycoor[j] >= h ) {xcoor[j]=xfirst[j];ycoor[j]=yfirst[j];}
        if (!ns){ eval('document.all'+'["Layer'+j+'"]'+'.style.left='+xcoor[j]);
  eval('document.all'+'["Layer'+j+'"]'+'.style.top='+ycoor[j]);}
        else {  eval('document.layers'+'["Layer'+j+'"]'+'.left='+xcoor[j]);
  eval('document.layers'+'["Layer'+j+'"]'+'.top='+ycoor[j]);}
 }
    setTimeout('doplay()',200); 
}


//-->
</SCRIPT>
<DIV id=Layer0><IMG height=121 src="absolute path of your image/image1.gif" width=250> </DIV>
<DIV id=Layer1><IMG height=200 src="absolute path of your image/image2.gif" width=135> </DIV>
<DIV id=Layer2><IMG height=105 src="absolute path of your image/image3.gif" width=250> </DIV>
<DIV id=Layer3><IMG height=147 src="absolute path of your image/image4.gif" width=165> </DIV>

Images can be added more you like as rain drops, snowflakes, clouds,adv, etc.

Average of ratings: Useful (1)
In reply to Joanna Tsai

Re: Nice floating Image Javascript code in header.html but unable to disappear

by Mauno Korpelainen -

Usually the problem is that either tags are not pasted to correct place or script is not working with all browsers. Here are some good image effects if this does not work: http://www.dynamicdrive.com/dynamicindex4/

onload=doplay() should be written inside the original body tag of moodle in theme header.html (just after word body).

It looks like <style> tag is missing before #layer0 and tags between <style> and </style> should be inside <head> and </head> or in some css file of your theme.

Script itself and those div tags should be inside body tags (you may paste it to beginning of  if home {...} tags too or to to end (to footer.html before </body>)

I could test it later...

In reply to Mauno Korpelainen

Re: Nice floating Image Javascript code in header.html but unable to disappear

by Joanna Tsai -
Thanks for your reply, your suggestion is right as I didn't explain it clearly above, these javascript do work well if you just wanna images drop and float randomly, however, I place it in the header.html, and  hope images float for some limit time maybe 30 seconds as some guests would not like pages with floating things always, so I hope someone can help to modify the javascript effect code.
In reply to Joanna Tsai

Re: Nice floating Image Javascript code in header.html but unable to disappear

by Mauno Korpelainen -

You could search timer scripts but there is another way to do this. Make two versions of your theme, one with javascript and one without it (secondversion) and use meta tag Refresh to load second version of theme after 30 seconds.

Look first at http://moodle.org/mod/forum/discuss.php?d=69425

If you paste

$CFG->allowthemechangeonurl = true;

to config.php (to allow session themes)

and add after <head>

<meta http-equiv="refresh" content="30; url=http://yourmoodle/index.php?&theme=secondversion">

(where secondversion is the name of your theme without that javascript)

first theme loads second theme after 30 seconds.