delaunay实现图片塌陷过渡动画效果代码
代码语言:html
所属分类:幻灯片
代码描述:delaunay实现图片塌陷过渡动画效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
body {
background-color: #000;
margin: 0;
overflow: hidden;
}
canvas {
position: absolute;
backface-visibility: hidden;
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
-ms-backface-visibility: hidden;
}
img {
position: absolute;
cursor: pointer;
}
#container {
position: absolute;
width: 768px;
height: 485px;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin: auto;
}
</style>
</head>
<body translate="no">
<div id="container"></div>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/delaunay-fast.1.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/TweenMax.min.js"></script>
<script>
// triangulation using https://github.com/ironwallaby/delaunay
const TWO_PI = Math.PI * 2;
var images = [],
imageIndex = 0;
var image,
imageWidth = 768,
imageHeight = 485;
var vertices = [],
indices = [],
fragments = [];
var container = document.getElementById('container');
var clickPosition = [imageWidth * 0.5, imageHeight * 0.5];
window.onload = function() {
TweenMax.set(container, {
perspective: 500
});
// images from reddit/r/wallpapers
var urls = [
'//repo.bfw.wiki/bfwrepo/image/5fc18ea484475.png',
'//repo.bfw.wiki/bfwrepo/image/5fc18ed75be96.png',
'//repo.bfw.wiki/bfwrepo/image/5fc18ea484475.png',
'//repo.bfw.wiki/bfwrepo/image/5fc18ed75be96.png',
],
image,
loaded = 0;
// very quick and dirty hack to load and display the first image asap
images[0] = image = new Image();
image.onload = function() {
if (++loaded === 1) {
imagesLoaded();
for (var i = 1; i < 4; i++) {
images[i] = image = new Image();
image.src = urls[i];
}
}
};
image.src = urls[0];
};
function imagesLoaded() {
placeImage(false);
triangulate();
shatter();
}
function placeImage(transitionIn) {
image = images[imageIndex];
if (++imageIndex === images.length) imageIndex = 0;
image.addEventListener('click', imageClickHandler);
container.appendChild(image);
.........完整代码请登录后点击上方下载按钮下载查看
网友评论0