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