Front-end training--Snowflake effect Plugin

Source: Internet
Author: User
Tags jquery library

Idle to Nothing, write JS practice practiced hand, today made a simple version of the Snowflake special effects background plug-in, share with you.

Here are a few thought steps and the corresponding code:

First, we're going to write a snowflake specimen and hide it, here we introduce the jquery library, as follows:
<! DOCTYPE html>

You can set the speed and size properties in the tab, Speed: "Slow,normal,fast"; Size: "Small,normal,big". Represents the speed and size of snowflakes, respectively.

Then, we need a class to produce a snowflake specimen.

Before we do that, we should know that the initial horizontal position of snowflakes should be random, so here is a function to produce a random position:

 var snowypic=$ ("img"). EQ (0);        Snowflake specimen//Snowflake position random number function Randomat () {var widthpos = Math.random (). toString (). Slice (0,5);         Widthpos =widthpos*1000;        if (Widthpos >= $ (window). Width ()) widthpos=$ (window). Width ()-100;     return widthpos;  }//Production snowflake specimen function Snowycreate (speed,size) {this.speed=speed;//snowflake Speed This.pos_x=randomat ();  Horizontal this.pos_y=0;        Ordinate var self=this;          This.create=function () {var random=math.random () +math.random ();  Random=random.tostring (). Slice (2,9);          The ID has a length limit of $ ("body"). Append ("

In the above code, I placed the Snowflake drop behavior function in the production snowflake class, and borrowed the new () instance to re-open the context and execute the function body mechanism of the production create () after the snowflake instance as a parameter into the drift () function, to achieve the snowflake produced and with a drop action.

Finally, I extracted the parameters set in the snowflake specimen and placed them in the options object, and at last read each parameter rendering.

Specific code and file complete package on GitHub: Https://github.com/Johnharvy/snowy-plugin.

If you have a little interest, give me some encouragement!

Front-end training--Snowflake effect Plugin

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.