Home > Web Front-end > JS Tutorial > body text

Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skills

WBOY
Release: 2016-05-16 16:26:35
Original
2466 people have browsed it

Winter is here, and many blog spaces have added Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsflake effects, so I went to see how they implemented the effects. There are several effect codes, so I brought them over. Friends in need can take them over and try them out.

Big picture of Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsflakes:

Four ways to use js code and plug-ins to achieve the Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsflake falling effect in wordpress_javascript skills

Effect code one

<script type="text/javascript" language="javascript">
(function() {
function k(a, b, c) {
if (a.addEventListener) a.addEventListener(b, c, false);
else a.attachEvent && a.attachEvent("on" + b, c)
}
function g(a) {
if (typeof window.onload != "function") window.onload = a;
else {
var b = window.onload;
window.onload = function() {
b();
a()
}
}
}
function h() {
var a = {};
for (type in {
Top: "",
Left: ""
}) {
var b = type == "Top" &#63; "Y": "X";
if (typeof window["page" + b + "Offset"] != "undefined")
a[type.toLowerCase()] = window["page" + b + "Offset"];
else {
b = document.documentElement.clientHeight &#63; document.documentElement: document.body;
a[type.toLowerCase()] = b["scroll" + type]
}
}
return a
}
function l() {
var a = document.body,
b;
if (window.innerHeight) b = window.innerHeight;
else if (a.parentElement.clientHeight) b = a.parentElement.clientHeight;
else if (a && a.clientHeight) b = a.clientHeight;
return b
}
function i(a) {
this.parent = document.body;
this.createEl(this.parent, a);
this.size = Math.random() * 5 + 5;
this.el.style.width = Math.round(this.size) + "px";
this.el.style.height = Math.round(this.size) + "px";
this.maxLeft = document.body.offsetWidth - this.size;
this.maxTop = document.body.offsetHeight - this.size;
this.left = Math.random() * this.maxLeft;
this.top = h().top + 1;
this.angle = 1.4 + 0.2 * Math.random();
this.minAngle = 1.4;
this.maxAngle = 1.6;
this.angleDelta = 0.01 * Math.random();
this.speed = 2 + Math.random()
}
var j = false;
g(function() {
j = true
});
var f = true;
window.createSnow = function(a, b) {
if (j) {
var c = [],
m = setInterval(function() {
f && b > c.length && Math.random()
< b * 0.0025 && c.push(new i(a)); ! f && !c.length && clearInterval(m);
for (var e = h().top, n = l(), d = c.length - 1; d >= 0; d--)
if (c[d]) if (c[d].top < e || c[d].top + c[d].size + 1 > e + n) {
c[d].remove();
c[d] = null;
c.splice(d, 1)
} else {
c[d].move();
c[d].draw()
}
},
40);
k(window, "scroll",
function() {
for (var e = c.length - 1; e >= 0; e--) c[e].draw()
})
} else g(function() {
createSnow(a, b)
})
};
window.removeSnow = function() {
f = false
};
i.prototype = {
createEl: function(a, b) {
this.el = document.createElement("img");
this.el.setAttribute
("src", b + "雪花图片的绝对链接地址");
this.el.style.position = "absolute";
this.el.style.display = "block";
this.el.style.zIndex = "99999";
this.parent.appendChild(this.el)
},
move: function() {
if (this.angle < this.minAngle || this.angle > this.maxAngle)
this.angleDelta = -this.angleDelta;
this.angle += this.angleDelta;
this.left += this.speed * Math.cos(this.angle * Math.PI);
this.top -= this.speed * Math.sin(this.angle * Math.PI);
if (this.left < 0) this.left = this.maxLeft;
else if (this.left > this.maxLeft) this.left = 0
},
draw: function() {
this.el.style.top = Math.round(this.top) + "px";
this.el.style.left = Math.round(this.left) + "px"
},
remove: function() {
this.parent.removeChild(this.el);
this.parent = this.el = null
}
}
})();
createSnow("", 40);
</script>
Copy after login

Copy and paste the above code directly into the Header or Footer file in the theme. If you only want the article page to be displayed, just add it directly to single. Below, we provide Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsflake pictures (required materials) to everyone, Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skills small pictures: You need to upload them to the current theme of your blog, and then change the link in the code to the location of the picture. The effect is as shown on this page.

Effect code two:

 <html>
<head>
<script>
function start(){
var array=new Array();
var canvas=document.getElementById("mycanvas");
var context=canvas.getContext("2d");
for(var i=0;i<50;i++){
var ShowFour ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skills=new showFour ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skills();
array.push(ShowFour ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skills);
}
time=setInterval(function (){
context.clearRect(0,0,canvas.width,canvas.height);
for(var i=0;i<array.length;i++){
array[i].move();
array[i].draw(context);
}
},500);
}
function showFour ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skills(){
var y=parseInt(Math.random()*50)*10;
var x=parseInt(Math.random()*80)*10;
this.draw=function(context){
context.font="50px Calibri";
context.fillText("*",x,y);
}
this.move=function(){
y+=20;
if(y>600){
y=0;
}
}
}
</script>
</head>
<body>
<input type="button" value="start" onclick="start()" />
<br/>
<canvas id="mycanvas" height="600px" width="600px" style="border: 3px solid blue"></canvas>
</body>
</html>
Copy after login

This effect is demonstrated as follows (it feels ugly, not recommended):

Effect code three

In fact, you can also use the let it Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skills plug-in to implement Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsflakes falling on your WordPress blog.

I won’t go into details about how to use the let it Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skills plug-in here. It is no different from other plug-in installations. You can directly download and upload the files in the let it Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skills folder to the /wp-content/plugins/ directory, and then To activate this plug-in, just set the plug-in in the WordPress admin panel menu. Or you can find it by searching directly in the back plug-in library.

let it Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skills official website: Click to visit

Effect code four

I saw a very powerful SnowStorm plug-in on the Internet. It's awesome. It seems that searching let it Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skills on Google will produce the code for Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skills and frost effects. It's very creative. If you think the children's shoes are good, you can go to the official website to check them out.

I found a simple random Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsflake falling effect code on the Internet to share with you (this effect is written in pure code. Snowflakes are *.):

Let’s briefly explain some of the functions inside:

1. letItSnow()

It’s Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsing (this sentence is still useless). Then call createSnow to generate Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsflakes.

2. createSnow()

Generate Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsflakes. Each Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsflake is an tag, put an "*" in it to simulate Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsflakes (Google's copy can't be downloaded, it actually displays as a space, I'm so surprised...), and then put it in a big The container is called Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsBox, and the generated individuals are pushed into iArray and collected. The Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsflake uses the absolute positioning method based on the Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsBox. The top is 0px, and the left uses Math.random()*window.screen.width, so that the Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsflake is randomly generated in the screen width.

Use color to control the color depth of Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsflakes to create depth of field, ranging from 0 to 200
Use fontSize to control the size of the Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsflakes, ranging from 10px to 15px
Use time to control the calling interval of Snowflake Falling, ranging from 40ms to 50ms
Use Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsInterval to control the interval between Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsflakes, ranging from 500ms to 1000ms

Then it calls itself recursively, continuously generating Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsflakes.

3. fallDown()

As the name suggests, it is to make Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsflakes fall. The falling speed is 2px, that is, each time it falls vertically 2px. Do a test at this time. If the Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsflake drops to a fixed height, that is, higher than the parent container, then remove it. This can reduce the pressure on the browser. Otherwise, too many Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsflakes will cause the browser to move slower and slower. Anyway, It has been removed from view by overflow:hidden. Out of sight is out of mind. Then call a windBlow function while descending vertically to make the Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsflakes fall more artistically.

4. windBlow()

The name seems to be like wind blowing, but it is actually the effect of wind blowing (this is even more useless. Haha.), using a Math.sin() to produce the effect of Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsflakes floating in the air, so that the Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsflakes will not be monotonous straight lines. Instead of falling, it falls in a serpentine shape. Control the falling interval so that the continuity is better and it looks more comfortable.

function letItSnow(){
	var Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsBox=document.getElementById("Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsBox");
	var iArray=new Array();
	createSnow(Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsBox,iArray);

}
function fallDown(temObj,iArray){
	var speed=2;
	var top=parseInt(temObj.style.top);
	if(top>510){//当到超过高度时候就删了它,减轻浏览器压力
		for(var i=0;i<iArray.length;i++){
			if(temObj==iArray[i]){
				iArray.splice(i,1);
				var Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsBox=document.getElementById("Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsBox");
				Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsBox.removeChild(temObj);
				return false;
			}
		}
	}
	temObj.style.top=top+speed+"px";
	var wind=windBlow(temObj,top);
	temObj.style.left=parseInt(temObj.style.left)+wind*2+"px";
}
function windBlow(temObj,top){
	if(parseInt(Math.random())%2==1)
	return Math.sin(top/16);
	else return Math.cos(top/16);
}
function createSnow(Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsBox,iArray){
	var temObj=document.createElement("i");
	var temText=document.createTextNode("*");
	temObj.appendChild(temText);
	temObj.style.left=parseInt(Math.random()*window.screen.width)+"px";
	temObj.style.top="0px";
	var temNum=parseInt(Math.random()*200);
	temObj.style.color="#"+temNum.toString(16)+temNum.toString(16)+temNum.toString(16);
	iArray.push(temObj);
	Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsBox.appendChild(temObj);
	var temNum=0;
	while(temNum<10){
		temNum=parseInt(Math.random()*15);
	}
	temObj.style.fontSize=temNum+"px";

	var time=0;
	while(time<40){
		time=parseInt(Math.random()*50);
	}
	temObj.timer=setInterval(function(){
		fallDown(temObj,iArray);								
	},time);
	var Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsInterval=0;
	while(Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsInterval<500){
		Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsInterval=parseInt(Math.random()*1000);
	}
	var createTimer=setTimeout(function(){
		createSnow(Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsBox,iArray);	
		clearTimeout(createTimer);
	},Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skillsInterval);
}
Copy after login

Demo address: http://demo.jb51.net/js/2014/Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skills/

Okay, this ends the four effect codes. Hope it can help friends in need. If you have any questions, you can leave a message below.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template