从这里开始http://jsfiddle.net/5pR46/1/:
CSS
#wrapper canvas {
position: relative;
}
#wrapper canvas {
border: 1px solid red;
position: absolute;
background-color: transparent;
}
HTML
<div id="wrapper">
<canvas id="myCanvas" width="578" height="200"></canvas>
<canvas id="myCanvas2" width="578" height="200"></canvas>
</div>
JavaScript
function drawRadial(elemId, startColor, endColor, x0, y0, r0, x1, y1, r1) {
var canvas = document.getElementById(elemId);
var context = canvas.getContext('2d');
context.rect(0, 0, canvas.width, canvas.height);
// create radial gradient
var grd = context.createRadialGradient(x0, y0, r0, x1, y1, r1);
grd.addColorStop(0, startColor);
grd.addColorStop(1, endColor);
context.fillStyle = grd;
context.fill();
delete canvas;
delete context;
delete grd;
}
drawRadial('myCanvas', 'rgba(248,173,133,1.0)', 'rgba(0,0,0,0.0)', 50, 25, 110, 300, 50, 400);
drawRadial('myCanvas2', 'rgba(213,215,155,1.0)', 'rgba(0,0,0,0.0)', 500, 150, 110, 500, 50, 600);
您可以根据需要添加任意数量的图层。只需添加另一个;
<canvas id="myCanvas#" width="578" height="200"></canvas>
..#
你的层的新编号在哪里(将它们保持在正确的顺序以获得正确的结果。你甚至可以使用 JavaScript,只是从一个空开始,然后#wrapper
用 -incremented ID 动态填充它canvas
,然后绑定完整的绘图过程。为您提供超级干净的代码,同时保持对内容的控制。
玩弄坐标和径向线的大小,它很快就会像你想要的那样适合。我会把剩下的创意留给你;)