html 代码
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title></title>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- </head>
- <style>
- *{margin: 0;padding: 0;}
- #canvas{display: block;background: #000}
- </style>
- <body>
- <canvas id="canvas"></canvas>
- </body>
- <script>
- window.onload = function () {
- var canvas = document.getElementById('canvas');
- var ctx = canvas.getContext('2d');
- canvas.width = 700;
- canvas.height = 700;
- var radius = 0;
- function drawCircle() {
- ctx.beginPath();
- ctx.arc(100, 100, radius, 0, Math.PI * 2);
- ctx.closePath();
- ctx.lineWidth = 2;
- ctx.strokeStyle = 'rgba(255,255,50,1)';
- ctx.stroke();
- radius += 0.5;
- if (radius> 30) {
- radius = 0;
- }
- }
- function render() {
- var prev = ctx.globalCompositeOperation;
- ctx.globalCompositeOperation = 'destination-in';
- ctx.globalAlpha = 0.95;
- ctx.fillRect(0, 0, canvas.width, canvas.height);
- ctx.globalCompositeOperation = prev;
- drawCircle();
- };
- var testtimer = setInterval(function () {
- render();
- }, 20);
- }
- </script>
- </html>
来源: http://www.qdfuns.com/article/38556/71b18b2281b6bbba79346579da88d79c.html