【Canvas】线性渐变色例子-垂直方向渐变
作者:互联网
<!DOCTYPE html> <html lang="utf-8"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <head> <title>线性渐变色例子-垂直方向渐变</title> </head> <body onl oad="draw()"> <canvas id="myCanvus" width="400px" height="400px" style="border:1px dashed black;"> 出现文字表示你的浏览器不支持HTML5 </canvas> </body> </html> <script type="text/javascript"> <!-- function draw(){ var canvas=document.getElementById('myCanvus'); canvas.width=400; canvas.height=400; var ctx=canvas.getContext('2d'); ctx.translate(200,200); // 从上到下垂直渐变,注意之前有平移 var linegrad=ctx.createLinearGradient(0,-200,0,200); linegrad.addColorStop(0,"white");// 白色 linegrad.addColorStop(1,"navy");// 海蓝 ctx.fillStyle=linegrad; ctx.fillRect(-200,-200,400,400); }; //--> </script>
效果:
END
标签:Canvas,渐变色,渐变,垂直,例子,线性 来源: https://www.cnblogs.com/pyhy/p/15780316.html