canvas烟花绽放美丽动画效果代码
代码语言:html
所属分类:粒子
代码描述:canvas烟花绽放美丽动画效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <style> * { margin: 0; padding: 0; font-family: "微软雅黑"; } .box { width: 80vw; margin: 0 auto; background: #EFEFEF; position: absolute; /*left: 0;*/ left: calc(50% - 40vw); /*水平居中*/ top: 0; } #name { padding: 60px; font-size: 40px; font-weight: 900; text-align: center; background: url(images/6.jpg) no-repeat center; /*以盒子内的文字作为裁剪区域向外裁剪,文字之外的区域都将被裁剪掉*/ -webkit-background-clip: text; -webkit-text-fill-color: transparent; /*文字颜色填充*/ } h1 { letter-spacing: 3px; height: 70px; line-height: 70px; background: #ccc; text-align: center; -webkit-text-stroke: 1px #000; /*字体描边*/ -webkit-text-fill-color: transparent; /*谷歌内核特有的属性*/ } #bt { height: 50px; line-height: 50px; background: deepskyblue; text-align: center; color: #fff; cursor: pointer; } </style> </head> <body id="bodyid"> <canvas id="canvas"></canvas> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/jquery-3.2.1.min.js"></script> <script> $(function() { var canvas = $('#canvas')[0]; canvas.width = $(window).width(); canvas.height = $(window).height(); var ctx = canvas.getContext('2d'); // resize $(window).on('resize', function() { canvas.width = $(window).width(); canvas.height = $(window).height(); ctx.fillStyle = '#000'; ctx.fillRect(0, 0, canvas.width, canvas.height); }); // init ctx.fillStyle = '#000'; ctx.fillRect(0, 0, canvas.width, canvas.height); // objects var listFire = []; var listFirework = []; var fireNumber = 10; var center = { x: canvas.width / 2, y: canvas.height / 1.5 }; var range = 100; for (var i = 0; i < fireNumber; i++) { var fire = { x: Math.random() * range / 2 - range / 4 + center.x, y: Math.random() * range * 2 + canvas.height, size: Math.random() + 0.5, fill: '#fd1', vx: Math.random() - 0.5, vy: -(Math.random() + 4), ax: Math.random() * 0.02 - 0.01, far: Math.random() * range + (center.y - range) }; fire.base = { x: fire.x, y: fire.y, vx: fire.vx }; // listFire.push(fire); } function randColor() { var r = Math.floor(Math.random() * 256); var g = Math.floor(Math.random() * 256); var b = Math.floor(Math.random() * 256); var color = 'rgb($r, $g, $b)'; color = color.replace('$r', r); color = color.replace('$g', g); color = color.replace('$b', b); return color; } (function loop() { requestAnimationFrame(loop); update().........完整代码请登录后点击上方下载按钮下载查看
网友评论0