DuMmWiaM.com, Personal Showreel, lab & resources for web development.

jSnow 1.1 implementation, space invaders snowflakes

During the Christmas 2009 season, I will use jSnow 1.1 to decorate byteme.gr with a special type of snowflakes...space invader snowflakes! The code used is very simple and it consists of two parts A) PHP and B) the jSnow implementation. I am using PHP because I want it to (j)snow after 19:00 and until 8:00 in the morning (Greek is set to +2:00 GMT), not all day long :).

So here is the full php code that controls the appearance of the script according to the time and prints out the javascript code:

  1. <?php
  2. $HOUR = date('G');
  3. if ($HOUR>=19 || $HOUR<8) {
  4. echo '<script type="text/javascript" src="'.$R.'/js/jsnow.js"></script>';
  5. echo '$(function() {';
  6. echo '$().jSnow({flakes:20,flakeCode:[$R+"/images/invader_flake1.gif",$R+"/images/invader_flake2.gif"],zIndex:9999});';
  7. }
  8. />

Wherever you see $R (in PHP or JS) is a variable for the root path of the website. It's a very common shortcut that I use to reference the website's root folder in JavaSCript and PHP.

I hope this short tip and demonstration will help you with jSnow.

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
Image CAPTCHA
Enter the characters (without spaces) shown in the image.