Jump to content

Javascript snow


Sherzod

Recommended Posts

Dear friends!

 

Allow to present an interesting JS code.
As you guessed, it is JS snow (and not only).
Let's give our UniGUI application, a little "liven up" ... :)

 

post-906-0-03278300-1450287430_thumb.png

 

Example of use:

 

1.

/files/snow.png

post-906-0-37953400-1450286611.png

 

2. MainForm.Script... add:

<script type="text/javascript">
    //snow_img = "/files/snow.gif";

    snow_img = "/files/snow.png";

    // EXTRA: You can adjust the numbers of snowflakes you want on each page...
    snow_no = 15;

    if (typeof(window.pageYOffset) == "number") {
        snow_browser_width = window.innerWidth;
        snow_browser_height = window.innerHeight;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        snow_browser_width = document.body.offsetWidth;
        snow_browser_height = document.body.offsetHeight;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        snow_browser_width = document.documentElement.offsetWidth;
        snow_browser_height = document.documentElement.offsetHeight;
    } else {
        snow_browser_width = 500;
        snow_browser_height = 500;
    }

    snow_dx = [];
    snow_xp = [];
    snow_yp = [];
    snow_am = [];
    snow_stx = [];
    snow_sty = [];

    for (i = 0; i < snow_no; i++) {
        snow_dx[i] = 0;
        snow_xp[i] = Math.random() * (snow_browser_width - 50);
        snow_yp[i] = Math.random() * snow_browser_height;
        snow_am[i] = Math.random() * 20;
        snow_stx[i] = 0.02 + Math.random() / 10;
        snow_sty[i] = 0.7 + Math.random();
        if (i > 0) document.write("<\div id=\"snow_flake" + i + "\" style=\"position:absolute;z-index:100000\"><\img src=\"" + snow_img + "\" border=\"0\"><\/div>");
        else document.write("<\div id=\"snow_flake0\" style=\"position:absolute;z-index:100000\"><\/div>");
    }

    function SnowStart() {
        for (i = 0; i < snow_no; i++) {
            snow_yp[i] += snow_sty[i];
            if (snow_yp[i] > snow_browser_height - 50) {
                snow_xp[i] = Math.random() * (snow_browser_width - snow_am[i] - 30);
                snow_yp[i] = 0;
                snow_stx[i] = 0.02 + Math.random() / 10;
                snow_sty[i] = 0.7 + Math.random();
            }
            snow_dx[i] += snow_stx[i];
            document.getElementById("snow_flake" + i).style.top = snow_yp[i] + "px";
            document.getElementById("snow_flake" + i).style.left = snow_xp[i] + snow_am[i] * Math.sin(snow_dx[i]) + "px";
        }
        snow_time = setTimeout("SnowStart()", 10);
    }
    SnowStart();
</script>

Try...

 

Best regards.

  • Upvote 4
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...