+ Reply to Thread
Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 21

Thread: cool holiday script for you guys

  1. #1
    Join Date
    Oct 2004
    Location
    Florida
    Posts
    2,132

    Default cool holiday script for you guys

    This is a cool script for slowly falling snow flakes.

    ####begin script#####
    <SCRIPT language=JavaScript1.2>



    var snowsrc="images/snow.gif"
    var no = 6;

    var ns4up = (document.layers) ? 1 : 0;
    var ie4up = (document.all) ? 1 : 0;

    var dx, xp, yp;
    var am, stx, sty;
    var i, doc_width = 800, doc_height = 600;

    if (ns4up) {
    doc_width = self.innerWidth;
    doc_height = self.innerHeight;
    } else if (ie4up) {
    doc_width = document.body.clientWidth;
    doc_height = document.body.clientHeight;
    }

    dx = new Array();
    xp = new Array();
    yp = new Array();
    am = new Array();
    stx = new Array();
    sty = new Array();

    for (i = 0; i < no; ++ i) {
    dx[i] = 0;
    xp[i] = Math.random()*(doc_width-50);
    yp[i] = Math.random()*doc_height;
    am[i] = Math.random()*20;
    stx[i] = 0.02 + Math.random()/10;
    sty[i] = 0.7 + Math.random();
    if (ns4up) {
    if (i == 0) {
    document.write("<layer name='dot"+ i +"' left='15' top='15' visibility='show'><img src='"+snowsrc+"' border='0'></a></layer>");
    } else {
    document.write("<layer name='dot"+ i +"' left='15' top='15' visibility='show'><img src='"+snowsrc+"' border='0'></layer>");
    }
    } else if (ie4up) {
    if (i == 0) {
    document.write("<div id='dot"+ i +"' style='POSITION: absolute; Z-INDEX: "+ i +"; VISIBILITY: visible; TOP: 15px; LEFT: 15px;'><img src='"+snowsrc+"' border='0'></a></div>");
    } else {
    document.write("<div id='dot"+ i +"' style='POSITION: absolute; Z-INDEX: "+ i +"; VISIBILITY: visible; TOP: 15px; LEFT: 15px;'><img src='"+snowsrc+"' border='0'></div>");
    }
    }
    }

    function snowNS() {
    for (i = 0; i < no; ++ i) {
    yp[i] += sty[i];
    if (yp[i] > doc_height-50) {
    xp[i] = Math.random()*(doc_width-am[i]-30);
    yp[i] = 0;
    stx[i] = 0.02 + Math.random()/10;
    sty[i] = 0.7 + Math.random();
    doc_width = self.innerWidth;
    doc_height = self.innerHeight;
    }
    dx[i] += stx[i];
    document.layers["dot"+i].top = yp[i];
    document.layers["dot"+i].left = xp[i] + am[i]*Math.sin(dx[i]);
    }
    setTimeout("snowNS()", 20);
    }

    function snowIE() {
    for (i = 0; i < no; ++ i) {
    yp[i] += sty[i];
    if (yp[i] > doc_height-50) {
    xp[i] = Math.random()*(doc_width-am[i]-30);
    yp[i] = 0;
    stx[i] = 0.02 + Math.random()/10;
    sty[i] = 0.7 + Math.random();
    doc_width = document.body.clientWidth;
    doc_height = document.body.clientHeight;
    }
    dx[i] += stx[i];
    document.all["dot"+i].style.pixelTop = yp[i];
    document.all["dot"+i].style.pixelLeft = xp[i] + am[i]*Math.sin(dx[i]);
    }
    setTimeout("snowIE()", 20);
    }

    if (ns4up) {
    snowNS();
    } else if (ie4up) {
    snowIE();
    }

    </SCRIPT>
    ####end script####
    Last edited by kyle422; 12-14-2005 at 06:17 PM.

  2. #2
    Join Date
    Jun 2004
    Location
    Auckland, New Zealand
    Posts
    594

    Default Re: cool holiday script for you guys

    it snows in Florida at Xmas? I thought your Xmas would be like ours...
    Attached Images

  3. #3
    Join Date
    Sep 2004
    Location
    Czech Republic
    Posts
    159

    Default Re: cool holiday script for you guys

    This is shorter and should work with all browsers. I hope.

    Code:
    	<script type="text/javascript">
    		var snowsrc = "snehova-vlocka.gif" // source of snowflake
    		var no = 6; // no. of snowflakes
    		var doc_width, doc_height;
    
    		if (window.innerWidth || window.innerHeight)//opera Netscape 6 Netscape 4x Mozilla 
    		{ 
    			doc_width = window.innerWidth; 
    			doc_height = window.innerHeight; 
    		} 
    
    		if (document.body.clientWidth || document.body.clientHeight)//IE Mozilla 
    		{ 
    			doc_width = document.body.clientWidth; 
    			doc_height = document.body.clientHeight; 
    		} 
    
    		dx = new Array();
    		xp = new Array();
    		yp = new Array();
    		am = new Array();
    		stx = new Array();
    		sty = new Array();
    
    		for ( i=0; i < no; i++ )
    		{
    			dx[i] = 0;
    			xp[i] = Math.random() * (doc_width - 50);
    			yp[i] = Math.random() * doc_height;
    			am[i] = Math.random() * 20;
    			stx[i] = 0.02 + Math.random()/10;
    			sty[i] = 0.7 + Math.random();
    			
    			document.write("<div id='dot"+ i +"' style='POSITION: absolute; Z-INDEX: "+ i +"; VISIBILITY: visible; TOP: 15px; LEFT: 15px;'><img src='"+snowsrc+"' border='0'></div>");
    
    		}
    
    		function snow(doc_width, doc_height)
    		{
    			for (i = 0; i < no; ++ i)
    			{
    				sflake = new Array();
    				sflake[i] = document.getElementById('dot'+i); // getting all snowflakes
    				yp[i] += sty[i];
    				if ( yp[i] > doc_height - 50 )
    				{
    					xp[i] = Math.random()*(doc_width-am[i]-30);
    					yp[i] = 0;
    					stx[i] = 0.02 + Math.random()/10;
    					sty[i] = 0.7 + Math.random();
    				}
    				dx[i] += stx[i];
    
    				sflake[i].style.top = yp[i] + 'px';
    				sflake[i].style.left = xp[i] + am[i] * Math.sin(dx[i]) + 'px';
    			}
    			setTimeout("snow(doc_width, doc_height)", 20);
    		}
    
                     snow(doc_width, doc_height);
    	</script>
    Vlado Tovarnak

    "The more I want to get something done, the less I call it work."
    "In order to win, you must expect to win."

    by RICHARD BACH


    http://www.ValuesGuide.com is now producing and providing leads for real estate agents

  4. #4
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    4,846

    Default Re: cool holiday script for you guys

    Nice Script.

    Vlado, that worked fine in IE6, Netscape 7.2, Opera 7.5, and Firefox.

  5. #5
    Join Date
    Oct 2004
    Location
    Florida
    Posts
    2,132

    Default Re: cool holiday script for you guys

    Quote Originally Posted by sarahk
    it snows in Florida at Xmas? I thought your Xmas would be like ours...
    Yes, the snow is not very fitting for Florida or my site, but I figured I have to have something to celebrate the holidays.

  6. #6
    Join Date
    Nov 2004
    Location
    Richmond, VA
    Posts
    273

    Default Re: cool holiday script for you guys

    Way cool!

    I wanted to do something, but didn't want to turn into a "Christmas" template...

    Thank you... Thank you...

    PS... Kyle... You should put a lit-up palm tree on your site, like the Corona commercial! That's always cool!
    Last edited by CafeMonkey; 12-13-2004 at 05:04 AM.

  7. #7
    Join Date
    Oct 2004
    Location
    Florida
    Posts
    2,132

    Default Re: cool holiday script for you guys

    Quote Originally Posted by CafeMonkey
    PS... Kyle... You should put a lit-up palm tree on your site, like the Corona commercial! That's always cool!
    That would be quite funny.
    Kyle

  8. #8
    Join Date
    Oct 2004
    Location
    Florida
    Posts
    2,132

    Default Re: cool holiday script for you guys

    Quote Originally Posted by CafeMonkey
    Way cool!

    I wanted to do something, but didn't want to turn into a "Christmas" template...

    Thank you... Thank you...

    PS... Kyle... You should put a lit-up palm tree on your site, like the Corona commercial! That's always cool!
    I noticed that you use the script that Vlado put up, which I couldn't get to work properly. It is also funky looking on your site. Have you looked at it?

  9. #9
    Join Date
    Nov 2004
    Location
    Richmond, VA
    Posts
    273

    Default Re: cool holiday script for you guys

    Funky looking in what way? In what browser?

    I just copied the script as he put it up, and copied the snowflake file.

  10. #10
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    4,846

    Default Re: cool holiday script for you guys

    That does look a little different. Check out how the snowflakes float down the page on Kyle's site.

    On your page the snowflakes stop right after they start giving the impression of "blinking."

+ Reply to Thread
Page 1 of 3 1 2 3 LastLast

Posting Permissions

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