Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
html, body { margin: 0; padding: 0; overflow: hidden; } canvas { background: #000; }
JavaScript
window.human = false; var canvasEl = document.querySelector('.fireworks'); var ctx = canvasEl.getContext('2d'); var numberOfParticules = 30; var pointerX = 0; var pointerY = 0; var tap = ('ontouchstart' in window || navigator.msMaxTouchPoints) ? 'touchstart' : 'mousedown'; var colors = ['#FF1461', '#18FF92', '#5A87FF', '#FBF38C']; function setCanvasSize() { canvasEl.width = window.innerWidth * 2; canvasEl.height = window.innerHeight * 2; canvasEl.style.width = window.innerWidth + 'px'; canvasEl.style.height = window.innerHeight + 'px'; canvasEl.getContext('2d').scale(2, 2); } function updateCoords(e) { pointerX = e.clientX || e.touches[0].clientX; pointerY = e.clientY || e.touches[0].clientY; } function setParticuleDirection(p) { var angle = anime.random(0, 360) * Math.PI / 180; var value = anime.random(50, 180); var radius = [-1, 1][anime.random(0, 1)] * value; return { x: p.x + radius * Math.cos(angle), y: p.y + radius * Math.sin(angle) } } function createParticule(x,y) { var p = {}; p.x = x; p.y = y; p.color = colors[anime.random(0, colors.length - 1)]; p.radius = anime.random(16, 32); p.endPos = setParticuleDirection(p); p.draw = function() { ctx.beginPath(); ctx.arc(p.x, p.y, p.radius, 0, 2 * Math.PI, true); ctx.fillStyle = p.color; ctx.fill(); } return p; } function createCircle(x,y) { var p = {}; p.x = x; p.y = y; p.color = '#FFF'; p.radius = 0.1; p.alpha = .5; p.lineWidth = 6; p.draw = function() { ctx.globalAlpha = p.alpha; ctx.beginPath(); ctx.arc(p.x, p.y, p.radius, 0, 2 * Math.PI, true); ctx.lineWidth = p.lineWidth; ctx.strokeStyle = p.color; ctx.stroke(); ctx.globalAlpha = 1; } return p; } function renderParticule(anim) { for (var i = 0; i < anim.animatables.length; i++) { anim.animatables[i].target.draw(); } } function animateParticules(x, y) { var circle = createCircle(x, y); var particules = []; for (var i = 0; i < numberOfParticules; i++) { particules.push(createParticule(x, y)); } anime.timeline().add({ targets: particules, x: function(p) { return p.endPos.x; }, y: function(p) { return p.endPos.y; }, radius: 0.1, duration: anime.random(1200, 1800), easing: 'easeOutExpo', update: renderParticule }) .add({ targets: circle, radius: anime.random(80, 160), lineWidth: 0, alpha: { value: 0, easing: 'linear', duration: anime.random(600, 800), }, duration: anime.random(1200, 1800), easing: 'easeOutExpo', update: renderParticule, offset: 0 }); } var render = anime({ duration: Infinity, update: function() { ctx.clearRect(0, 0, canvasEl.width, canvasEl.height); } }); document.addEventListener(tap, function(e) { window.human = true; render.play(); updateCoords(e); animateParticules(pointerX, pointerY); }, false); var centerX = window.innerWidth / 2; var centerY = window.innerHeight / 2; function autoClick() { if (window.human) return; animateParticules( anime.random(centerX-50, centerX+50), anime.random(centerY-50, centerY+50) ); anime({duration: 200}).finished.then(autoClick); } autoClick(); setCanvasSize(); window.addEventListener('resize', setCanvasSize, false);
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Anime.js 烟花画布演示-jq22.com</title> <script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script> <style>
</style> </head> <body>
<script>
</script>
</body> </html>
2012-2021 jQuery插件库版权所有
jquery插件
|
jq22工具库
|
网页技术
|
广告合作
|
在线反馈
|
版权声明
沪ICP备13043785号-1
浙公网安备 33041102000314号