下载地址:

http://www.html5tricks.com/jquery-html5-christ-snow.html

演示地址:

http://www.html5tricks.com/jquery-html5-christ-snow.html

个人的demo:

新建并且引用以下js文件:

(function($){$.snowfall = function(element, options){var    defaults = {flakeCount : 35,flakeColor : '#ffffff',flakeIndex: 999999,minSize : 1,maxSize : 2,minSpeed : 1,maxSpeed : 5,round : false,shadow : false,collection : false,collectionHeight : 40,deviceorientation : false},options = $.extend(defaults, options),random = function random(min, max){return Math.round(min + Math.random()*(max-min)); };$(element).data("snowfall", this);            // Snow flake objectfunction Flake(_x, _y, _size, _speed, _id){// Flake propertiesthis.id = _id; this.x  = _x;this.y  = _y;this.size = _size;this.speed = _speed;this.step = 0;this.stepSize = random(1,10) / 100;if(options.collection){this.target = canvasCollection[random(0,canvasCollection.length-1)];}var flakeMarkup = $(document.createElement("div")).attr({'class': 'snowfall-flakes', 'id' : 'flake-' + this.id}).css({'width' : this.size, 'height' : this.size, 'background' : options.flakeColor, 'position' : 'absolute', 'top' : this.y, 'left' : this.x, 'fontSize' : 0, 'zIndex' : options.flakeIndex});if($(element).get(0).tagName === $(document).get(0).tagName){$('body').append(flakeMarkup);element = $('body');}else{$(element).append(flakeMarkup);}this.element = document.getElementById('flake-' + this.id);// Update function, used to update the snow flakes, and checks current snowflake against boundsthis.update = function(){this.y += this.speed;if(this.y > (elHeight) - (this.size  + 6)){this.reset();}this.element.style.top = this.y + 'px';this.element.style.left = this.x + 'px';this.step += this.stepSize;if (doRatio === false) {this.x += Math.cos(this.step);} else {this.x += (doRatio + Math.cos(this.step));}// Pileup checkif(options.collection){if(this.x > this.target.x && this.x < this.target.width + this.target.x && this.y > this.target.y && this.y < this.target.height + this.target.y){var ctx = this.target.element.getContext("2d"),curX = this.x - this.target.x,curY = this.y - this.target.y,colData = this.target.colData;if(colData[parseInt(curX)][parseInt(curY+this.speed+this.size)] !== undefined || curY+this.speed+this.size > this.target.height){if(curY+this.speed+this.size > this.target.height){while(curY+this.speed+this.size > this.target.height && this.speed > 0){this.speed *= .5;}ctx.fillStyle = "#fff";if(colData[parseInt(curX)][parseInt(curY+this.speed+this.size)] == undefined){colData[parseInt(curX)][parseInt(curY+this.speed+this.size)] = 1;ctx.fillRect(curX, (curY)+this.speed+this.size, this.size, this.size);}else{colData[parseInt(curX)][parseInt(curY+this.speed)] = 1;ctx.fillRect(curX, curY+this.speed, this.size, this.size);}this.reset();}else{// flow to the sidesthis.speed = 1;this.stepSize = 0;if(parseInt(curX)+1 < this.target.width && colData[parseInt(curX)+1][parseInt(curY)+1] == undefined ){// go leftthis.x++;}else if(parseInt(curX)-1 > 0 && colData[parseInt(curX)-1][parseInt(curY)+1] == undefined ){// go rightthis.x--;}else{//stopctx.fillStyle = "#fff";ctx.fillRect(curX, curY, this.size, this.size);colData[parseInt(curX)][parseInt(curY)] = 1;this.reset();}}}}}if(this.x > (elWidth) - widthOffset || this.x < widthOffset){this.reset();}}// Resets the snowflake once it reaches one of the bounds setthis.reset = function(){this.y = 0;this.x = random(widthOffset, elWidth - widthOffset);this.stepSize = random(1,10) / 100;this.size = random((options.minSize * 100), (options.maxSize * 100)) / 100;this.speed = random(options.minSpeed, options.maxSpeed);}}// Private varsvar flakes = [],flakeId = 0,i = 0,elHeight = $(element).height(),elWidth = $(element).width(),widthOffset = 0,snowTimeout = 0;// Collection Piece ******************************if(options.collection !== false){var testElem = document.createElement('canvas');if(!!(testElem.getContext && testElem.getContext('2d'))){var canvasCollection = [],elements = $(options.collection),collectionHeight = options.collectionHeight;for(var i =0; i < elements.length; i++){var bounds = elements[i].getBoundingClientRect(),canvas = document.createElement('canvas'),collisionData = [];if(bounds.top-collectionHeight > 0){                                    document.body.appendChild(canvas);canvas.style.position = 'absolute';canvas.height = collectionHeight;canvas.width = bounds.width;canvas.style.left = bounds.left + 'px';canvas.style.top = bounds.top-collectionHeight + 'px';for(var w = 0; w < bounds.width; w++){collisionData[w] = [];}canvasCollection.push({element :canvas, x : bounds.left, y : bounds.top-collectionHeight, width : bounds.width, height: collectionHeight, colData : collisionData});}}}else{// Canvas element isnt supportedoptions.collection = false;}}// ************************************************// This will reduce the horizontal scroll bar from displaying, when the effect is applied to the whole pageif($(element).get(0).tagName === $(document).get(0).tagName){widthOffset = 25;}// Bind the window resize event so we can get the innerHeight again$(window).bind("resize", function(){  elHeight = $(element).height();elWidth = $(element).width();}); // initialize the flakesfor(i = 0; i < options.flakeCount; i+=1){flakeId = flakes.length;flakes.push(new Flake(random(widthOffset,elWidth - widthOffset), random(0, elHeight), random((options.minSize * 100), (options.maxSize * 100)) / 100, random(options.minSpeed, options.maxSpeed), flakeId));}// This adds the style to make the snowflakes round via border radius property if(options.round){$('.snowfall-flakes').css({'-moz-border-radius' : options.maxSize, '-webkit-border-radius' : options.maxSize, 'border-radius' : options.maxSize});}// This adds shadows just below the snowflake so they pop a bit on lighter colored web pagesif(options.shadow){$('.snowfall-flakes').css({'-moz-box-shadow' : '1px 1px 1px #555', '-webkit-box-shadow' : '1px 1px 1px #555', 'box-shadow' : '1px 1px 1px #555'});}// On newer Macbooks Snowflakes will fall based on deviceorientationvar doRatio = false;if (options.deviceorientation) {$(window).bind('deviceorientation', function(event) {doRatio = event.originalEvent.gamma * 0.1;});}// this controls flow of the updating snowfunction snow(){for( i = 0; i < flakes.length; i += 1){flakes[i].update();}snowTimeout = setTimeout(function(){snow()}, 30);}snow();// Public Methods// clears the snowflakesthis.clear = function(){$(element).children('.snowfall-flakes').remove();flakes = [];clearTimeout(snowTimeout);};};// Initialize the options and the plugin$.fn.snowfall = function(options){if(typeof(options) == "object" || options == undefined){        return this.each(function(i){(new $.snowfall(this, options)); });    }else if (typeof(options) == "string") {return this.each(function(i){var snow = $(this).data('snowfall');if(snow){snow.clear();}});}};
})(zepto);

View Code

使用方式,请务必在页面完全加载之后使用以下代码,其他具体参数请查看演示地址的源码

$(document).snowfall({round : true, minSize: 2, maxSize:4}); // add rounded

转载于:https://www.cnblogs.com/CyLee/p/6216135.html

jquery/zepto 圣诞节雪花飞扬相关推荐

  1. 雪花飞舞的java程序_jqmcsnow jquery圣诞节雪花飘落网页特效,配上了 树和雪景,在加上本效果实现的 飞 JavaScript 238万源代码下载- www.pudn.com...

    文件名称: jqmcsnow下载 收藏√  [ 5  4  3  2  1 ] 开发工具: Java 文件大小: 146 KB 上传时间: 2014-09-28 下载次数: 0 详细说明:jquery ...

  2. HTML圣诞节代码,圣诞节贺卡源代码,实现圣诞节雪花飘落效果

    HTML圣诞节代码,圣诞节贺卡源代码,实现圣诞节雪花飘落效果 完整代码下载地址:HTML圣诞节代码,圣诞节贺卡源代码,实现圣诞节雪花飘落效果 index.html <!DOCTYPE html& ...

  3. 5分钟搞定jQuery zepto.js 面向对象插件

    今天分享一下快速使用jQuery zepto.js的技巧,需要的记得收藏 1.jQuery的引入:本地下载jQuery(后面简称jq)的源文件,开发版本使用非min版,线上使用min版,zepto.j ...

  4. [jQuery] Zepto的点透问题如何解决?

    [jQuery] Zepto的点透问题如何解决? 1."点透"是什么你可能碰到过在列表页面上创建一个弹出层,弹出层有个关闭的按钮,你点了这个按钮关闭弹出层后后,这个按钮正下方的内容 ...

  5. jQuery / zepto ajax 全局默认设置

    jQuery / zepto 的 $.ajax 方法需要配置很多选项, 有些是很常用的每个 ajax 请求都要用到的, 可以全局设置, 避免每次都写. 注意: 此处用的 jQuery 版本是 1.8. ...

  6. jQuery/Zepto的Bootstrap轮播图中图片自适应宽高并居中插件

    2019独角兽企业重金招聘Python工程师标准>>> 今天写了一下午带晚上的jQuery/Zepto的Bootstrap轮播图插件,功能是能够根据当前较短的一边实现自适应宽度,并且 ...

  7. 【Visual C++】游戏开发五十 浅墨DirectX教程十八 雪花飞扬 实现唯美的粒子系统

    分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章.分享知识,造福人民,实现我们中华民族伟大复兴! 本系列文 ...

  8. 【Visual C++】游戏开发五十 浅墨DirectX教程十八 雪花飞扬:实现唯美的粒子系统...

    本系列文章由zhmxy555(毛星云)编写,转载请注明出处. 文章链接:http://blog.csdn.net/zhmxy555/article/details/8744805 作者:毛星云(浅墨) ...

  9. 基于jQuery/zepto的单页应用(SPA)搭建方案

    这里介绍一个基于jquery或zepto的单页面应用方案,遵循尽可能简单的原则,使大家一目了然,只需配置一个路由,之后完全按照jq日常写法即可完成.可做学习使用,也可修改后用于一些业务逻辑简单的spa ...

最新文章

  1. 2016-2017 ACM-ICPC CHINA-Final(EC-final) 题解(10 / 12)
  2. php中js代码放在哪,JavaScript
  3. C#调用API向外部程序发送数据(转载)
  4. 阿里云原生开源大家族加入中科院软件所开源软件供应链点亮计 - 暑期 2021
  5. XtraGrid RepositoryItemCheckEdit 显示状态以及单选多选问题
  6. Spring mvc中@RequestMapping 6个基本用法小结
  7. 怎么更好掌握Web前端技术?JS的跨域是怎么回事?
  8. Spring MVC 常用注解之 Controller 篇
  9. c语言srand函数怎么用_Excel统计指定内容出现次数,用函数怎么写?人人都能看懂的公式...
  10. 如何在苹果Mac上快速将表情符号添加到电子邮件?
  11. 挂载Linux镜像文件,使用镜像文件安装依赖
  12. 欢迎大家访问吐槽人网 http://www.tucaoman.com/
  13. android 调色盘颜色选取
  14. CUDA加速——共享内存介绍及其应用
  15. 展锐物联网芯片8910DM获德国电信认证
  16. 用java语言画一个可视化日历
  17. 上海工程技术大学c语言试卷,上海工程技术大学2009_2010C语言试卷A.doc
  18. 【编码】数据库编码报错
  19. 屏幕监控软件怎样监控电脑的扩展屏?
  20. MA、WMA、EMA、EXPMA区别及公式详述

热门文章

  1. 解决:idea运行scala程序,报错:Error:scalac: bad option: -make:transitive
  2. 伟大的程序员同志们累了看看我这笑话,巨搞笑!
  3. 7-7 韩信点兵 (10 分)
  4. 模糊集合和隶属度详解
  5. (原创)报考计算机博士之前应该注意的几个问题---写给应届硕士毕业生
  6. 【百科】详解阿里云技术核心——飞天
  7. 计算机地理绘图软件叫什么,地理教师如何选择理想的绘图软件 ──基于对常用绘图软件的比较与分析...
  8. [解疑][TI]TI毫米波雷达系列(一):Texas Instruments德州仪器 相关软件安装及使用时问题汇总,持续更新......
  9. 淘宝账号 支付宝账号 阿里旺旺账号
  10. 10.32/10.33 rsync通过服务同步 10.34 linux系统日志 10.35 scre