search
HomeWeb Front-endHTML TutorialCSS3实现雪花飘落动画_html/css_WEB-ITnose

<html><head>	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">	<meta name="viewport" content="width=device-width,initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">	<meta name="apple-mobile-web-app-capable" content="yes">	<meta name="format-detection" content="telephone=no, email=no">	<title>snowflake</title>	<script type="text/javascript" src="http://w3school.com.cn/jquery/jquery-1.11.1.min.js"></script>	<style type="text/css">		body {			padding: 0;			margin: 0;			background-color: #333;			font-size: 14px;			color: #BCBCBC;		}		input {			border: solid 0px #DDD;			border-radius: 5px;			padding: 5px 10px;			width: 120px;		}		button {			border: solid 0px #CCC;			border-radius: 5px;			background-color: #FFF;			padding: 5px 10px;		}		#sky {			width: 100%;			max-width: 640px;			height: 100%;			background-color: #A39;			margin: 0 auto;			position: relative;    		overflow: hidden;		}		.snowflake {			width: 50px;			height: 50px;			border-radius: 50px;			background-color: rgba(255, 255, 255, 0.5);			position: absolute;			top: 10px;			left: 100px;			display: inline-block;			transition: top 2s;			-moz-transition: top 2s;/* Firefox 4 */			-webkit-transition: top 2s;/* Safari 和 Chrome */			-o-transition: top 2s;			transition-timing-function: cubic-bezier(0.25,0.1,0.25,1);			-moz-transition-timing-function: cubic-bezier(0.25,0.1,0.25,1);			-webkit-transition-timing-function: cubic-bezier(0.25,0.1,0.25,1);			-o-transition-timing-function: cubic-bezier(0.25,0.1,0.25,1);		}		#operate {			text-align: right;		}		#operate div {			margin: 10px;		}	</style></head><body>	<div id="sky"></div>	<div id="operate">		<div>			<label>下雪频率(ms): <input name="rate" type="number" min="1" /></label>		</div>		<div>			<label>融化时间(ms): <input name="melt" type="number" min="0" /></label>		</div>		<div>			<button id="start-or-stop" onclick="startOrStop()">start</button>		</div>	</div>	<script type="text/javascript">	var $sky = $('#sky');	var maxTop = $sky.height() - 5;// 地面高度值(px)	var rate = 60;// 飘落频率(ms)	var flakeSize = 10;// 单片雪花宽高值(px)	var melt = 2000;// 融化时间(ms)	// 初始化雪花	function snowflake(size, alpha, top, left) {		var s = document.createElement('div');		$(s).css({			'width': size,			'height': size,			'border-radius': size,			'background-color': 'rgba(255,255,255,' + alpha + ')',			'top': -50,			'left': left,		}).addClass('snowflake');		return s;	}	// 雪花飘落并融化	function dift($s) {		$s.css('top', maxTop + (flakeSize - $s.width()) / 2);		setTimeout(function() {			$s.remove();		}, 2000 + melt);	}	// 开始动画	var animateId = -1;	var it = false;	function start() {		if(!it) {			it = setInterval(function() {				// 初始化雪花				var id = 's_' + (++animateId);				var size = Math.random() * flakeSize + 2;				var alpha = Math.random() * 0.7 + 0.1;				var left = Math.random() * $(window).width();				var s = snowflake(size, alpha, 0, left);				var $s = $(s).attr('id', id);				$sky.get(0).appendChild(s);				// 雪花飘落				setTimeout(function() {					dift($s);				}, 100);				if(animateId > 10000) {// 避免越界					animateId = 0;				}			}, rate);			$('#start-or-stop').html('stop');		}	}	start();	// 停止动画	function stop() {		clearInterval(it);		it = false;		$('#start-or-stop').html('start');	}	// 开始或暂停动画	function startOrStop() {		if(!it) {			start();		} else {			stop();		}	}	// 重启动画	function restart() {		stop();		start();	}	$(function() {		// 监听rate输入框		var minRate = 1, maxRate = 3000;		$('input[name="rate"]').val(rate).on('change', function() {			rate = parseInt($(this).val());			if(rate < minRate) {				rate = minRate;				$(this).val(rate);			} else if(rate > maxRate) {				rate = maxRate;				$(this).val(rate);			}			restart();		}).prop({			min: minRate,			max: maxRate		});		// 监听melt输入框		var minMalt = 0, maxMelt = 100000;		$('input[name="melt"]').val(melt).on('change', function() {			melt = parseInt($(this).val());			if(melt < minMalt) {				melt = minMalt;				$(this).val(melt);			} else if(melt > maxMelt) {				melt = maxMelt;				$(this).val(melt);			}			restart();		}).prop({			min: minMalt,			max: maxMelt		});	});	</script></body></html>


Statement
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
The Role of HTML: Structuring Web ContentThe Role of HTML: Structuring Web ContentApr 11, 2025 am 12:12 AM

The role of HTML is to define the structure and content of a web page through tags and attributes. 1. HTML organizes content through tags such as , making it easy to read and understand. 2. Use semantic tags such as, etc. to enhance accessibility and SEO. 3. Optimizing HTML code can improve web page loading speed and user experience.

HTML and Code: A Closer Look at the TerminologyHTML and Code: A Closer Look at the TerminologyApr 10, 2025 am 09:28 AM

HTMLisaspecifictypeofcodefocusedonstructuringwebcontent,while"code"broadlyincludeslanguageslikeJavaScriptandPythonforfunctionality.1)HTMLdefineswebpagestructureusingtags.2)"Code"encompassesawiderrangeoflanguagesforlogicandinteract

HTML, CSS, and JavaScript: Essential Tools for Web DevelopersHTML, CSS, and JavaScript: Essential Tools for Web DevelopersApr 09, 2025 am 12:12 AM

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

The Roles of HTML, CSS, and JavaScript: Core ResponsibilitiesThe Roles of HTML, CSS, and JavaScript: Core ResponsibilitiesApr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

Is HTML easy to learn for beginners?Is HTML easy to learn for beginners?Apr 07, 2025 am 12:11 AM

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

What is an example of a starting tag in HTML?What is an example of a starting tag in HTML?Apr 06, 2025 am 12:04 AM

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

How to use CSS's Flexbox layout to achieve centering alignment of dotted line segmentation effect in menu?How to use CSS's Flexbox layout to achieve centering alignment of dotted line segmentation effect in menu?Apr 05, 2025 pm 01:24 PM

How to design the dotted line segmentation effect in the menu? When designing menus, it is usually not difficult to align left and right between the dish name and price, but how about the dotted line or point in the middle...

What HTML elements does the online code editor use to implement code input?What HTML elements does the online code editor use to implement code input?Apr 05, 2025 pm 01:21 PM

HTML Element Analysis in Web Code Editor Many online code editors allow users to enter HTML, CSS, and JavaScript code. Recently, someone proposed...

See all articles

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 agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.