html画布敲碎的视频,html5 canvas碎纸屑空中飘落动画特效
特效描述:html5 canvas碎纸屑 空中飘落动画特效。canvas绘制空中飘落的纸屑动画特效。
代码结构
1. HTML代码
"use strict";
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Progress = function () {
function Progress() {
var param = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
_classCallCheck(this, Progress);
this.timestamp = null;
this.duration = param.duration || Progress.CONST.DURATION;
this.progress = 0;
this.delta = 0;
this.progress = 0;
this.isLoop = !!param.isLoop;
this.reset();
}
Progress.prototype.reset = function reset() {
this.timestamp = null;
};
Progress.prototype.start = function start(now) {
this.timestamp = now;
};
Progress.prototype.tick = function tick(now) {
if (this.timestamp) {
this.delta = now - this.timestamp;
this.progress = Math.min(this.delta / this.duration, 1);
if (this.progress >= 1 && this.isLoop) {
this.start(now);
}
return this.progress;
} else {
return 0;
}
};
_createClass(Progress, null, [{
key: "CONST",
get: function get() {
return {
DURATION: 1000
};
}
}]);
return Progress;
}();
var Confetti = function () {
function Confetti(param) {
_classCallCheck(this, Confetti);
this.parent = param.elm || document.body;
this.canvas = document.createElement("canvas");
this.ctx = this.canvas.getContext("2d");
this.width = param.width || this.parent.offsetWidth;
this.height = param.height || this.parent.offsetHeight;
this.length = param.length || Confetti.CONST.PAPER_LENGTH;
this.yRange = param.yRange || this.height * 2;
this.progress = new Progress({
duration: param.duration,
isLoop: true
});
this.rotationRange = typeof param.rotationLength === "number" ? param.rotationRange : 10;
this.speedRange = typeof param.speedRange === "number" ? param.speedRange : 10;
this.sprites = [];
this.canvas.style.cssText = ["display: block", "position: absolute", "top: 0", "left: 0", "pointer-events: none"].join(";");
this.render = this.render.bind(this);
this.build();
this.parent.append(this.canvas);
this.progress.start(performance.now());
requestAnimationFrame(this.render);
}
Confetti.prototype.build = function build() {
for (var i = 0; i < this.length; ++i) {
var canvas = document.createElement("canvas"),
ctx = canvas.getContext("2d");
canvas.width = Confetti.CONST.SPRITE_WIDTH;
canvas.height = Confetti.CONST.SPRITE_HEIGHT;
canvas.position = {
initX: Math.random() * this.width,
initY: -canvas.height - Math.random() * this.yRange
};
canvas.rotation = this.rotationRange / 2 - Math.random() * this.rotationRange;
canvas.speed = this.speedRange / 2 + Math.random() * (this.speedRange / 2);
ctx.save();
ctx.fillStyle = Confetti.CONST.COLORS[Math.random() * Confetti.CONST.COLORS.length | 0];
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.restore();
this.sprites.push(canvas);
}
};
Confetti.prototype.render = function render(now) {
var progress = this.progress.tick(now);
this.canvas.width = this.width;
this.canvas.height = this.height;
for (var i = 0; i < this.length; ++i) {
this.ctx.save();
this.ctx.translate(this.sprites[i].position.initX + this.sprites[i].rotation * Confetti.CONST.ROTATION_RATE * progress, this.sprites[i].position.initY + progress * (this.height + this.yRange));
this.ctx.rotate(this.sprites[i].rotation);
this.ctx.drawImage(this.sprites[i], -Confetti.CONST.SPRITE_WIDTH * Math.abs(Math.sin(progress * Math.PI * 2 * this.sprites[i].speed)) / 2, -Confetti.CONST.SPRITE_HEIGHT / 2, Confetti.CONST.SPRITE_WIDTH * Math.abs(Math.sin(progress * Math.PI * 2 * this.sprites[i].speed)), Confetti.CONST.SPRITE_HEIGHT);
this.ctx.restore();
}
requestAnimationFrame(this.render);
};
_createClass(Confetti, null, [{
key: "CONST",
get: function get() {
return {
SPRITE_WIDTH: 9,
SPRITE_HEIGHT: 16,
PAPER_LENGTH: 100,
DURATION: 8000,
ROTATION_RATE: 50,
COLORS: ["#EF5350", "#EC407A", "#AB47BC", "#7E57C2", "#5C6BC0", "#42A5F5", "#29B6F6", "#26C6DA", "#26A69A", "#66BB6A", "#9CCC65", "#D4E157", "#FFEE58", "#FFCA28", "#FFA726", "#FF7043", "#8D6E63", "#BDBDBD", "#78909C"]
};
}
}]);
return Confetti;
}();
(function () {
var DURATION = 8000,
LENGTH = 120;
new Confetti({
width: window.innerWidth,
height: window.innerHeight,
length: LENGTH,
duration: DURATION
});
setTimeout(function () {
new Confetti({
width: window.innerWidth,
height: window.innerHeight,
length: LENGTH,
duration: DURATION
});
}, DURATION / 2);
})();
html画布敲碎的视频,html5 canvas碎纸屑空中飘落动画特效相关推荐
- HTML5 canvas绘制雪花飘落动画(需求分析、知识点、程序编写分布详解)
HTML5 canvas绘制雪花飘落动画(需求分析.知识点.程序编写分布详解) 原文:HTML5 canvas绘制雪花飘落动画(需求分析.知识点.程序编写分布详解) 看到网上很多展示html5雪花飞动 ...
- html 产生烟雾效果,html5 canvas抽象模糊烟雾动画特效
特效描述:html5 canvas 抽象模糊 烟雾动画特效.html5 canvas绘制彩色模糊的烟雾动画.抽象模糊的烟雾动画特效 代码结构 1. 引入CSS 2. 引入JS 3. HTML代码 vo ...
- HTML5实现的树叶飘落动画特效
以下是一个基于HTML5实现的树叶飘落动画特效: <!DOCTYPE html> <html> <head><title>树叶飘落动画特效</ti ...
- android 五彩纸屑动画,利用H5实现Canvas五彩纸屑飘落动画特效
特效描述:利用H5实现 Canvas 五彩纸屑飘落 动画特效.利用H5实现Canvas五彩纸屑飘落动画特效 代码结构 1. HTML代码 "use strict"; var _cr ...
- html5 雨滴效果,html5 canvas下雨滴掉落动画特效
特效描述:html5 canvas 雨滴掉落动画 动画特效.html5 canvas绘制下雨场景动画.雨滴动画. 代码结构 1. 引入JS 2. HTML代码 // TO DO // Remove r ...
- html语音播放动画,html5 canvas+js音频可视化动画特效
html5 canvas+js实现的音频可视化动画特效,选择一首本地音频文件播放查看效果. 查看演示 下载资源: 13 次 下载资源 下载积分: 20 积分 js代码 window.onload = ...
- php实现下雪场景,html5 canvas逼真下雪场景动画特效
这是一款效果十分逼真的html5 canvas下雪场景动画特效插件.这款下雪特效是基于Jason Brown的Snowfall jquery plugin的基础上制作的.在Snowfall jquer ...
- html5 canvas实现雷达扫描动画特效
先看一下最终效果 实现思路 绘制4个圆 绘制一个十字线 绘制一个扫描的指针 让指针转起来 雷达构造函数 function Radar(){this.renderArr=[];//待渲染对象存储数组th ...
- 基于 HTML5 Canvas 实现的文字动画特效
前言 文字是网页中最基本的元素,一般我们在网页上都是展示的静态文字,但是就效果来说,还是比较枯燥的.文字淡入淡出的动画效果在项目中非常实用,如果有某些关键的文字,可以通过这种动态的效果来提醒用户阅读. ...
最新文章
- maven打包 jar中没有主清单属性
- 疯子的算法总结(六) 简单排序总 选择排序+插入排序+比较排序+冒泡排序
- Linux实用代码--文件系统操作
- 完全实战-从零开始配置服务器
- java sql 联表查询系统_Spring Hibernate JPA 联表查询 复杂查询(转)
- abap判断包含字符当中包含小数点_剑指Offer整理3 -- 栈和队列 + 数学和字符串
- winform checkbox要点击两次_真正牛X的人生,必须经历两次失败!(深度)
- mysql查询优化not in,mysql not in如何优化
- 网页中引用两个css冲突怎么办
- centos配置ssh免密码登录
- Pandas系列(十四)数据转换函数map、apply、applymap以及分组apply
- ffmpeg API变更 2009-03-01—— 2017-05-09变更
- 用钩子程序实现根据一个表的字段更新另一个表的字段
- 三线一控电动球阀、三线两控电动球阀、两线制断电开阀、两线制断电关阀四类电动球阀的区别
- 关键词选择与维护教程
- 【数学建模】数学建模学习2---整数规划(例题+matlab代码实现)
- 中国云计算产业2016年度点评
- php上传图片并预览
- .Net 常用的ORM框架
- MIMO信道的信道容量