帝王谷资源网 Design By www.wdxyy.com
今天要为大家带来一款html5 canvas实现的图片玻璃碎片特效。图片以玻璃碎片的形式出现到界面中,然后似玻璃被打碎的效果渐消息。效果图如下:

一款html5 canvas实现的图片玻璃碎片特效 

源码下载 

html代码:


复制代码代码如下:
<img src="/UploadFiles/2021-03-30/city_copy.jpg"><div id="container" style="-webkit-perspective: 500px;">
<div>
<script src="delaunay.js"><script src="TweenMax.min.js">

js代码:

复制代码代码如下:
// canvas settings
var imageWidth = 768,
imageHeight = 485;
var vertices = [],
indices,
boxes = [];
var image,
fragments = [],
container = document.getElementById('container');
window.onload = function () {
image = document.getElementById('src_img');
triangulate();
makeBoxes();
makeFragments();
};
function triangulate() {
var x,
y,
dx = imageWidth / 8,
dy = imageHeight / 8,
offset = 0.5;
for (var i = 0; i <= imageWidth; i += dx) {
for (var j = 0; j <= imageHeight; j += dy) {
if (i && (i !== imageWidth)) x = i + randomRange(-dx * offset, dx * offset);
else x = i;
if (j && (j !== imageHeight)) y = j + randomRange(-dy * offset, dy * offset);
else y = j;
vertices.push([x, y]);
}
}
indices = Delaunay.triangulate(vertices);
}
function makeBoxes() {
var p0, p1, p2,
xMin, xMax,
yMin, yMax;
for (var i = 0; i < indices.length; i += 3) {
p0 = vertices[indices[i + 0]];
p1 = vertices[indices[i + 1]];
p2 = vertices[indices[i + 2]];
xMin = Math.min(p0[0], p1[0], p2[0]);
xMax = Math.max(p0[0], p1[0], p2[0]);
yMin = Math.min(p0[1], p1[1], p2[1]);
yMax = Math.max(p0[1], p1[1], p2[1]);
boxes.push({
x: xMin,
y: yMin,
w: xMax - xMin,
h: yMax - yMin
});
}
}
function makeFragments() {
var p0, p1, p2,
box,
fragment;
TweenMax.set(container, { perspective: 500 });
var tl0 = new TimelineMax({ repeat: -1 });
for (var i = 0; i < indices.length; i += 3) {
p0 = vertices[indices[i + 0]];
p1 = vertices[indices[i + 1]];
p2 = vertices[indices[i + 2]];
box = boxes[i / 3];
fragment = new Fragment(p0, p1, p2, box);
var rx = randomRange(30, 60) * ((i % 2) ? 1 : -1);
var ry = randomRange(30, 60) * ((i % 2) ? -1 : 1);
var tl1 = new TimelineMax();
TweenMax.set(fragment.canvas, {
y: box.y - 1000
});
tl1.to(fragment.canvas, randomRange(0.9, 1.1), {
y: box.y,
ease: Back.easeOut
});
tl1.to(fragment.canvas, 0.5, {
z: -100,
ease: Cubic.easeIn,
delay: 0.4
});
tl1.to(fragment.canvas, randomRange(1, 1.2), {
rotationX: rx,
rotationY: ry,
z: 250,
alpha: 0,
ease: Cubic.easeOut
});
tl0.insert(tl1);
fragments.push(fragment);
container.appendChild(fragment.canvas);
}
}
function randomRange(min, max) {
return min + (max - min) * Math.random();
}
Fragment = function (v0, v1, v2, box) {
this.v0 = v0;
this.v1 = v1;
this.v2 = v2;
this.box = box;
this.canvas = document.createElement('canvas');
this.canvas.width = this.box.w;
this.canvas.height = this.box.h;
this.canvas.style.width = this.box.w + 'px';
this.canvas.style.height = this.box.h + 'px';
this.ctx = this.canvas.getContext('2d');
TweenMax.set(this.canvas, {
x: this.box.x,
y: this.box.y
});
this.ctx.translate(-this.box.x, -this.box.y);
this.ctx.beginPath();
this.ctx.moveTo(this.v0[0], this.v0[1]);
this.ctx.lineTo(this.v1[0], this.v1[1]);
this.ctx.lineTo(this.v2[0], this.v2[1]);
this.ctx.closePath();
this.ctx.clip();
this.ctx.drawImage(image, 0, 0);
}; //@ sourceURL=pen.js
标签:
html5,canvas,玻璃碎片

帝王谷资源网 Design By www.wdxyy.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
帝王谷资源网 Design By www.wdxyy.com

《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线

暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。

艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。

《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。