圣诞节雪花效果,pc端
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" type="text/css" href="css/snow.css">
<style type="text/css">
.box{width: 100%; height: 900px; background: #000;}
</style>
</head>
<body>
<div class="box"></div>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/snow.js"></script>
</body>
</html>
snow.css
/*雪花飘落*/
.snow-container {
position: fixed;
top:;
left:;
width: 100%;
pointer-events: none;
z-index:;
} .snow-container .snow {
position: absolute;
background: #fff;
-webkit-border-radius: 50%;
border-radius: 50%;
-webkit-box-shadow: 0 0 15px rgba(255, 255, 255, 0.8);
box-shadow: 0 0 15px rgba(255, 255, 255, 0.8);
background: url(../images/snow.png) no-repeat\9;
} :root .snow-container .snow { }
snow.js
var isSupportCss3 = (function(){
var ret = /MSIE (\d+\.\d+)/.exec(navigator.userAgent);
if( !ret || ret[1] > 9 ){
return true;
}
return false;
})();
(function () {
Function.prototype.bind = Function.prototype.bind || function(){
var self = this,
context = [].shift.call(arguments),
args = [].slice.call(arguments);
return function(){
return self.apply(context, [].concat.call(args, [].slice.call(arguments)));
}
};
function getRandom(min, max) {
return min + Math.random()*(max-min);
}
function getWindowSize() {
return {
clientW: window.innerWidth || document.documentElement.clientWidth,
clientH: window.innerHeight || document.documentElement.clientHeight
}
}
var clientSize = getWindowSize();
var body = document.body;
function Snow(container, opts) {
this.container = container;
this.opts = opts;
this.create();
}
Snow.prototype = {
create: function () {
this.el = document.createElement("div");
this.el.className = 'snow';
this.el.style["width"] = this.opts.snowWidth + "px";
this.el.style["height"] = this.opts.snowHeight + "px";
this.el.style["top"] = -this.opts.snowHeight + "px";
this.el.style["-webkit-transition"] = "all " + this.opts.speed + "ms linear";
this.el.style["transition"] = "all " + this.opts.speed + "ms linear";
this.container.appendChild(this.el);
this.fall();
},
fall: function () {
var self = this;
var left = getRandom(0, clientSize.clientW - this.opts.snowWidth);
var destLeft = getRandom(-300, 300);
var scale = getRandom(0.6, 1);
this.el.style["left"] = left + "px";
this.el.style["-ms-transform"] = "scale("+ scale +")";
this.el.style["-webkit-transform"] = "scale("+ scale +")";
this.el.style["transform"] = "scale("+ scale +")";
body.offsetWidth;
var transformStyle = "scale("+ scale +") translate3d("+ destLeft +"px,"+ (clientSize.clientH + this.opts.snowHeight)*2 +"px,0px)";
this.el.style["-webkit-transform"] = transformStyle;
this.el.style["transform"] = transformStyle;
//当前页面失去焦点时,通过transitionend的方式移除this.el会有问题,因此通过这种方式移除
$({y: -this.opts.snowHeight, left: left}).animate({
y: (clientSize.clientH + this.opts.snowHeight)*(1/scale),
left: left + destLeft
}, {
easing: 'linear',
duration: this.opts.speed,
step: function ( value, obj) {
if( !isSupportCss3 ){
if( obj.prop == 'y' ) {
self.el.style.top = obj.now + "px";
}
if( obj.prop == 'left' ){
self.el.style.left = obj.now + "px";
}
}
},
complete: function () {
self.reset();
}
});
},
reset: function () {
try {
this.container.removeChild(this.el);
} catch (e){
console.error(e.message);
}
}
};
function SnowFall(opts){
this.opts = $.extend({
interval: 200,
speed: 15000,
snowWidth: 8,
snowHeight: 8
}, opts||{});
this.timer = null;
this.body = document.body;
this.init();
}
SnowFall.prototype = {
init: function () {
this.createLayout();
this.start();
},
start: function () {
new Snow(this.container, this.opts);
this.timer = setTimeout(function () {
this.start();
}.bind(this), this.opts.interval);
},
createLayout:function () {
this.container = document.createElement("div");
this.container.className = 'snow-container';
this.body.appendChild(this.container);
},
destroy: function () {
if( this.timer ) clearTimeout(this.timer);
this.container.parentNode.removeChild(this.container);
}
};
$(function () {
$(window).on("resize", function () {
clientSize = getWindowSize();
});
});
new SnowFall();
})();

圣诞节雪花效果,pc端的更多相关文章
- js实现一个可以兼容PC端和移动端的div拖动效果
前段时间写了一个简单的div拖动效果,不料昨天项目上正好需要一个相差不多的需求,就正好用上了,但是在移动端的时候却碰到了问题,拖动时候用到的三个事件:mousedown.mousemove.mouse ...
- Html5实现移动端、PC端 刮刮卡效果
刚从南方回来就分了一个刮刮卡效果的页面,特么的我在烦恼怎么用H5去实现这个效果呢,好不容易写出来了,产品居然说:“既然你可以写出来这个效果那当然好了,开始我只是打算让你实现点击就出现呢!”… … 尼玛 ...
- jquery简单的图片切换效果,支持pc端、移动端的banner图片切换开发
详细内容请点击 无意中看见了两年前写的一个图片切换,那会儿刚刚学习网页制作,可以说是我的第一个处女座的jquery图片切换效果.无聊之余对它的宽度稍稍做了一下修改,变成了支持pc端.手机端全屏的ban ...
- CSS3及JS简单实现选项卡效果(适配手机端和pc端)
想要适配手机端和pc端,有几种简单的方法,本人使用的是百分比分配的方法. *{ padding: 0; margin: 0; } body,html{ width: 100%; height: 100 ...
- 移动端页面a input去除点击效果及pc端切换
1 手机端页面a button input去除点击效果以及闪屏问题 添加: a, button, input { -webkit-tap-highlight-color: rgba(255, 0, 0 ...
- PC端触底效果反复触发的解决方案
最近在做一个PC端的项目,要求是在滑动到页面的底部的时候就动态的加载下一页的数据,代码实现思路如下: 首先,我们需要知道浏览器中有三个高度,分别是屏幕高度(outerHeight),文档容器高度(in ...
- 页面PC端 / 移动端整屏纵向翻页,点击/触摸滑动效果功能代码非插件
页面翻页,滑动功能示范代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset=& ...
- 关于pc端直播
写这篇文章首先是想给自己一个总结.整理,还有就是给那些 没有特别明白直播是怎么回事的人一点 思路 最近公司想要做pc端直播,作为一个自认为很菜的前端实在是不知从何下手,所以只能用国人最爱的百度,搜索了 ...
- JavaScript判断移动端及pc端访问不同的网站
JavaScript判断移动端及pc端访问不同的网站 现在很多网站都是分为两个版本,一个pc端的一个移动端的(响应式除外),针对这两个版本,就需要对访问的设备进行判断,如果是pc,就直接访问pc网站, ...
随机推荐
- OpenStack是什么,OpenStack详解
1. OpenStack是什么 OpenStack官方的解释很官方,而且从不同角度,也有不同的理解,OpenStack可以理解为一个云操作系统 OpenStack旗下包含了一组由社区维护的开源项目,他 ...
- 2.遍历XML即添加修改节点
1.xml <?xml version="1.0" encoding="utf-8" ?> <stories> <story ac ...
- gradle 构建scala程序
一.build.gradle 二.gradle build ===================== 执行scala scala main.scala
- 使用Mybatis
Pom.xml:项目对象模型,主要描述了项目---包括配置文件,开发者需要遵循的规则,缺陷管理系统,组织和licenses,项目的url,项目的依赖性以及其它与项目相关的因素.
- 结构型模式(二) 桥接模式(Bridge)
一.动机(Motivation) 在很多游戏场景中,会有这样的情况:[装备]本身会有的自己固有的逻辑,比如枪支,会有型号的问题,同时现在很多的游戏又在不同的介质平台上运行和使用,这样就使得游戏的[装备 ...
- Flask - 请求响应 | session | 闪现 | 请求扩展 | 中间件
请求响应 flask的请求信息都在request里 flask的响应方式有四剑客,也可以自定义响应 请求相关信息 # request.method 提交的方法 # request.args get请求 ...
- quiver()函数
1.quiver函数 一般用于绘制二维矢量场图,函数调用方法如下: 1 quiver(x,y,u,v) 该函数展示了点(x,y)对应的的矢量(u,v).其中,x的长度要求等于u.v的列数,y的长度要求 ...
- RANSEC算法
移步:https://blog.csdn.net/u010128736/article/details/53422070 clc;clear;close all; %%%二维直线拟合 %%%生成随机数 ...
- kafka的HA机制
1.kafka的HA机制:副本机制+消息同步+leader选举. 每个topic有多个partition,每个partition又有多个副本,这些副本当中也存在不同的角色,leader.followe ...
- [Flutter] Create a Customer widget
For example, we want to have to button, looks similar to FloatingActionButton: But in the doc, it sa ...