Home Web Front-end JS Tutorial Four ways to use js code and plug-ins to achieve the snowflake falling effect in wordpress_javascript skills

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

May 16, 2016 pm 04:26 PM

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.

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How do I create and publish my own JavaScript libraries? How do I create and publish my own JavaScript libraries? Mar 18, 2025 pm 03:12 PM

Article discusses creating, publishing, and maintaining JavaScript libraries, focusing on planning, development, testing, documentation, and promotion strategies.

How do I optimize JavaScript code for performance in the browser? How do I optimize JavaScript code for performance in the browser? Mar 18, 2025 pm 03:14 PM

The article discusses strategies for optimizing JavaScript performance in browsers, focusing on reducing execution time and minimizing impact on page load speed.

What should I do if I encounter garbled code printing for front-end thermal paper receipts? What should I do if I encounter garbled code printing for front-end thermal paper receipts? Apr 04, 2025 pm 02:42 PM

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

How do I debug JavaScript code effectively using browser developer tools? How do I debug JavaScript code effectively using browser developer tools? Mar 18, 2025 pm 03:16 PM

The article discusses effective JavaScript debugging using browser developer tools, focusing on setting breakpoints, using the console, and analyzing performance.

How do I use Java's collections framework effectively? How do I use Java's collections framework effectively? Mar 13, 2025 pm 12:28 PM

This article explores effective use of Java's Collections Framework. It emphasizes choosing appropriate collections (List, Set, Map, Queue) based on data structure, performance needs, and thread safety. Optimizing collection usage through efficient

How do I use source maps to debug minified JavaScript code? How do I use source maps to debug minified JavaScript code? Mar 18, 2025 pm 03:17 PM

The article explains how to use source maps to debug minified JavaScript by mapping it back to the original code. It discusses enabling source maps, setting breakpoints, and using tools like Chrome DevTools and Webpack.

Getting Started With Chart.js: Pie, Doughnut, and Bubble Charts Getting Started With Chart.js: Pie, Doughnut, and Bubble Charts Mar 15, 2025 am 09:19 AM

This tutorial will explain how to create pie, ring, and bubble charts using Chart.js. Previously, we have learned four chart types of Chart.js: line chart and bar chart (tutorial 2), as well as radar chart and polar region chart (tutorial 3). Create pie and ring charts Pie charts and ring charts are ideal for showing the proportions of a whole that is divided into different parts. For example, a pie chart can be used to show the percentage of male lions, female lions and young lions in a safari, or the percentage of votes that different candidates receive in the election. Pie charts are only suitable for comparing single parameters or datasets. It should be noted that the pie chart cannot draw entities with zero value because the angle of the fan in the pie chart depends on the numerical size of the data point. This means any entity with zero proportion

Who gets paid more Python or JavaScript? Who gets paid more Python or JavaScript? Apr 04, 2025 am 12:09 AM

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

See all articles