Javascript examples for Canvas:Stroke
Example of Filling Linear Gradient inside Canvas Shapes
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Example of Filling Linear Gradient inside Canvas Shapes</title> <style type="text/css"> canvas{/* w w w. j a v a 2 s .c om*/ border: 1px solid #000; } </style> <script type="text/javascript"> window.onload = function(){ var canvas = document.getElementById("myCanvas"); var context = canvas.getContext("2d"); context.rect(50, 50, 200, 100); var grd = context.createLinearGradient(0, 0, canvas.width, canvas.height); grd.addColorStop(0, '#8ED6FF'); grd.addColorStop(1, '#004CB3'); context.fillStyle = grd; context.fill(); context.stroke(); }; </script> </head> <body> <canvas id="myCanvas" width="300" height="200"></canvas> </body> </html>