www.webdeveloper.com
Results 1 to 10 of 10

Thread: Why wont it work?

  1. #1
    Join Date
    Oct 2004
    Posts
    5

    Why wont it work?

    Ok. So I got this nice little script here, drops leaves just fine on IE. Go to firefox and its in the corner!

    Code:
    num=15; //Smoothness depends on image file size, the smaller the size the more you can use!
    
    stopafter=10000; //seconds!
    
    
    
    
    
    //Pre-load images!
    
    pics=new Array("redleaf.gif","orngleaf.gif","ylowleaf.gif","grenleaf.gif","brwnleaf.gif"); 
    
    load=new Array();
    
    for(i=0; i < pics.length; i++){
    
     load[i]=new Image();
    
     load[i].src=pics[i];
    
    }
    
    stopafter*=1000;
    
    timer=null;
    
    y=new Array();
    
    x=new Array();
    
    s=new Array();
    
    s1=new Array();
    
    s2=new Array();
    
    if (document.layers){
    
     for (i=0; i < num; i++){
    
     randomleaf = pics[Math.floor(Math.random()*pics.length)];
    
     document.write("<LAYER NAME='leaf"+i+"' LEFT=0 TOP=0><img src="+randomleaf+"></LAYER>");
    
     }
    
    }
    
    if (document.all){
    
    document.write('<div style="position:absolute;top:0px;left:0px"><div style="position:relative">');
    
     for (i=0; i < num; i++){
    
     randomleaf = pics[Math.floor(Math.random()*pics.length)];
    
     document.write('<img id="leaf'+i+'" src="'+randomleaf+'" style="position:absolute;top:0px;left:0px">');
    
     }
    
     document.write('</div></div>');
    
    }
    
    if (!document.all&&!document.layers){
    
     for (i=0; i < num; i++){
    
     randomleaf = pics[Math.floor(Math.random()*pics.length)];
    
     document.write("<div id='leaf"+i+"' style='position:absolute;top:0px;left:0px'><img src="+randomleaf+"></div>");
    
     }
    
    }
    
    inih=(document.all)?window.document.body.clientHeight:window.innerHeight-100;
    
    iniw=(document.all)?window.document.body.clientWidth:window.innerWidth-100;
    
    for (i=0; i < num; i++){                                                                
    
     y[i]=Math.round(Math.random()*inih);
    
     x[i]=Math.round(Math.random()*iniw);
    
     s[i]=Math.random()*5+3;
    
     s1[i]=0;
    
     s2[i]=Math.random()*0.1+0.05;
    
    }
    
    function fall(){
    
    h=(document.all)?window.document.body.clientHeight:window.innerHeight;
    
    w=(document.all)?window.document.body.clientWidth:window.innerWidth;
    
    scy=(document.all)?document.body.scrollTop:window.pageYOffset;
    
    scx=(document.all)?document.body.scrollLeft:window.pageXOffset;
    
    for (i=0; i < num; i++){
    
    sy=s[i]*Math.sin(90*Math.PI/180);
    
    sx=s[i]*Math.cos(s1[i]);
    
    y[i]+=sy;
    
    x[i]+=sx; 
    
    if (y[i] > h){
    
     y[i]=-60;
    
     x[i]=Math.round(Math.random()*w);
    
     s[i]=Math.random()*5+3;
    
    }
    
    s1[i]+=s2[i];
    
    if (document.layers){
    
     document.layers["leaf"+i].left=x[i];
    
     document.layers["leaf"+i].top=y[i]+scy;
    
    }
    
    else{
    
     document.getElementById("leaf"+i).style.left=x[i];
    
     document.getElementById("leaf"+i).style.top=y[i]+scy;
    
    } 
    
    }
    
    timer=setTimeout('fall()',60);
    
    }
    
    fall();
    
    
    
    function dsbl(){
    
    for (i=0; i < num; i++){
    
     if (document.layers)
    
     document.layers["leaf"+i].visibility="hide";
    
     else
    
     document.getElementById("leaf"+i).style.visibility="hidden";
    
    }
    
    clearTimeout(timer);
    
    }
    
    setTimeout('dsbl()',stopafter);
    Whats the fix?

  2. #2
    Join Date
    May 2004
    Location
    Manhattan NY
    Posts
    6,028
    The gecko code doesn't include css positioning, the IE code does, that's why

  3. #3
    Join Date
    Oct 2004
    Posts
    5
    So if I lose the divs I wont have a problem?

  4. #4
    Join Date
    May 2004
    Location
    Manhattan NY
    Posts
    6,028
    No, use the same document.write statements for both. the IE one includes positioning, the other doesnt.

  5. #5
    Join Date
    Oct 2004
    Posts
    5
    I'm missing what you said. I know CSS Positioning isnt working in other 'gecko' browsers. How do I adjust my code so it does?

  6. #6
    Join Date
    May 2004
    Location
    Manhattan NY
    Posts
    6,028
    It isn't that it's not working, it isn't THERE. This is in the IE code
    style="position:absolute;top:0px;left:0px

    not present in the gecko code

  7. #7
    Join Date
    Oct 2004
    Posts
    5
    The gecko code, the gecko code. Where is my gecko code? I see nothing that tells the code to act differently for different browsers. So where isn't it THERE? Where should it be? Oh and I'm thickheaded if you haven't caught on already. lol

  8. #8
    Join Date
    May 2004
    Location
    Manhattan NY
    Posts
    6,028
    document.layers is for gecko, document.all is for IE. Actually that's an old script. It's outdated, in truth. You see what I posted? You see where it is, and then where it ISN'T? Well add it to where it isn't, in the document.layers section, the document.write statement.

  9. #9
    Join Date
    May 2004
    Location
    Manhattan NY
    Posts
    6,028
    Replace this document.write("<LAYER NAME='leaf"+i+"' LEFT=0 TOP=0><img src="+randomleaf+"></LAYER>");

    with this
    document.write("<LAYER NAME='leaf"+i+"' style="position:absolute;top:0px;left:0px><img src="+randomleaf+"></LAYER>");

  10. #10
    Join Date
    Oct 2004
    Posts
    5
    Ok I finally completely understood what you were getting at. I gave up on that script though, couldn't get it to work on Firefox. I've got a new one at http://brent.sifen7.com/fall/itemfall.js
    Now its from another site, and it worked just fine there. I've linked it to my head, just the like other site, but the images stay in the top left of my screen on Firefox! Errr soo messed up.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles