Javascript实现多彩雪花从天降散落效果的方法


Posted in Javascript onFebruary 02, 2015

本文实例讲述了Javascript实现多彩雪花从天降散落效果的方法。分享给大家供大家参考。具体分析如下:

先来看看运行效果,如下图所示:

Javascript实现多彩雪花从天降散落效果的方法

完整源代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head>

<title>Javascript多彩雪花从天降</title>

<style type="text/css">

.3waterSnow{display:block; overflow:hidden; font-size:12px; position:absolute};

body{background:#000;margin:0px}

html{overflow:hidden; background:#000;}

a{color:White;text-decoration:none}

.3waterTitle{color:red;height:140px;width:800px;margin:0px auto;text-align:center}

</style>

</head>
<body>
<script type="text/javascript">

var yanhua = "yanhua.3water.com";

var Fire = function (r, color) {

this.radius = r || 12;

this.color = color || "FF6600";

this.xpos = 0;

this.ypos = 0;

this.zpos = 0;

this.vx = 0;

this.vy = 0;

this.vz = 0;

this.mass = 1;

this.p = document.createElement("span");

this.p.className = "jb"+"51Snow";

this.p.innerHTML = "*";

this.p.style.fontSize = this.radius + "px";

this.p.style.color = "#" + this.color;

}

Fire.prototype = {

append: function (parent) {

parent.appendChild(this.p);

},

setSize: function (scale) {

this.p.style.fontSize = this.radius * scale + "px";

},

setPosition: function (x, y) {

this.p.style.left = x + "px";

this.p.style.top = y + "px";

},

setVisible: function (b) {

this.p.style.display = b ? "block" : "none";

}

}

var fireworks = function () {

var fires = new Array();

var count = 100;

var fl = 250;

var vpx = 500;

var vpy = 300;

var gravity = .3;

var floor = 200;

var bounce = -.8;

var timer;

return {

init: function () {

for (var i = 0; i < count; i++) {

var color = 0xFF0000;

color = (Math.random() * 0xFFFFFF).toString(16).toString().split(".")[0];

while (color.length < 6) {

color = "0" + color;

}

var fire = new Fire(12, color);

fires.push(fire);

fire.ypos = -100;

fire.vx = Math.random() * 6 - 3;

fire.vy = Math.random() * 6 - 3;

fire.vz = Math.random() * 6 - 3;

fire.append(document.body);

}

var that = this;

timer = setInterval(function () {

for (var i = 0; i < count; i++) {

that.move(fires[i]);

}

}, 30);

},

move: function (fire) {

fire.vy += gravity;

fire.xpos += fire.vx;

fire.ypos += fire.vy;

fire.zpos += fire.vz;

if (fire.ypos > floor) {

fire.ypos = floor;

fire.vy *= bounce;

}

if (fire.zpos > -fl) {

var scale = fl / (fl + fire.zpos);

fire.setSize(scale);

fire.setPosition(vpx + fire.xpos * scale,

vpy + fire.ypos * scale);

fire.setVisible(true);

} else {

fire.setVisible(false);

}

}

}

}

if (yanhua === 'yanhua.jb' + '51.' + 'net')

fireworks().init();
function 3waterSnow() {

window.location.reload();

} if (yanhua === 'yanhua.jb' + '51.' + 'net')

setInterval(3waterSnow, 6000);

</script>
</body>

</html>

希望本文所述对大家的javascript程序设计有所帮助。

Javascript 相关文章推荐
javascript document.execCommand() 常用解析
Dec 14 Javascript
myFocus slide3D v1.1.0 使用方法与下载
Jan 12 Javascript
仿百度联盟对联广告实现代码
Aug 30 Javascript
jQuery获得包含margin的outerWidth和outerHeight的方法
Mar 25 Javascript
javascript将DOM节点添加到文档的方法实例分析
Aug 04 Javascript
javascript判断图片是否加载完成的方法推荐
May 13 Javascript
所见即所得的富文本编辑器bootstrap-wysiwyg使用方法详解
May 27 Javascript
vue+iview写个弹框的示例代码
Dec 05 Javascript
三分钟学会用ES7中的Async/Await进行异步编程
Jun 14 Javascript
vue基础之模板和过滤器用法实例分析
Mar 12 Javascript
使用layui日期控件laydate对开始和结束时间进行联动控制的方法
Sep 06 Javascript
vue+spring boot实现校验码功能
May 27 Vue.js
jQuery及JS实现循环中暂停的方法
Feb 02 #Javascript
JQuery动画与特效实例分析
Feb 02 #Javascript
Javascript核心读书有感之词法结构
Feb 01 #Javascript
Javascript核心读书有感之语言核心
Feb 01 #Javascript
jQuery功能函数详解
Feb 01 #Javascript
jQuery动画与特效详解
Feb 01 #Javascript
jquery制作 随机弹跳的小球特效
Feb 01 #Javascript
You might like
香妃
2021/03/03 冲泡冲煮
PHP中for循环语句的几种变型
2007/03/16 PHP
解析如何去掉CodeIgniter URL中的index.php
2013/06/25 PHP
php利用新浪接口查询ip获取地理位置示例
2014/01/20 PHP
简单理解PHP的面向对象编程方式
2016/05/17 PHP
PHP 二维array转换json的实例讲解
2018/08/21 PHP
PHP如何搭建百度Ueditor富文本编辑器
2018/09/21 PHP
PDO::getAttribute讲解
2019/01/28 PHP
php面向对象程序设计入门教程
2019/06/22 PHP
PHP设计模式(六)桥连模式Bridge实例详解【结构型】
2020/05/02 PHP
NodeJS连接MongoDB数据库时报错的快速解决方法
2016/05/13 NodeJs
jQuery原理系列-css选择器的简单实现
2016/06/07 Javascript
jQuery实现的tab标签切换效果示例
2016/09/05 Javascript
详解JS模块导入导出
2017/12/20 Javascript
Vue中render方法的使用详解
2018/01/26 Javascript
解决vue自定义全局消息框组件问题
2019/11/22 Javascript
vue 使用v-for进行循环的实例代码详解
2020/02/19 Javascript
使用JavaScript获取扫码枪扫描得到的条形码的思路代码详解
2020/06/10 Javascript
[01:04:14]VP vs TNC 2018国际邀请赛小组赛BO2 第二场 8.17
2018/08/20 DOTA
python读取word文档的方法
2015/05/09 Python
python如何删除文件中重复的字段
2019/07/16 Python
python2 中 unicode 和 str 之间的转换及与python3 str 的区别
2019/07/25 Python
详解pandas中iloc, loc和ix的区别和联系
2020/03/09 Python
纯CSS3实现圆圈动态发光特效动画的示例代码
2021/03/08 HTML / CSS
俄罗斯运动鞋商店:Sneakerhead
2018/05/10 全球购物
莫斯科购买书籍网站:Book24
2020/01/12 全球购物
运动鞋、街头服装、手表和手袋的实时市场:StockX
2020/11/25 全球购物
武汉世纪畅想数字传播有限公司.NET笔试题
2014/07/22 面试题
涉外经济法专业毕业生推荐信
2013/11/24 职场文书
诚实守信道德模范事迹材料
2014/08/15 职场文书
关于运动会广播稿200字
2014/10/08 职场文书
领导批评与自我批评范文
2014/10/16 职场文书
党的群众路线教育实践活动整改落实情况报告
2014/10/28 职场文书
办公室卫生管理制度
2015/08/04 职场文书
写作技巧:优秀文案必备的3种结构
2019/08/19 职场文书
了解Redis常见应用场景
2021/06/23 Redis