h5-canvas-渐变

<!DOCTYPE html>
<html>
<body>

<canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.
</canvas>

<script>

var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");

ctx.font="20px '黑体'";
ctx.fillText("Hello World!",10,120);

ctx.font="30px Arial";
// Create gradient
var gradient=ctx.createLinearGradient(0,0,c.width,0);
gradient.addColorStop("0","tomato");
gradient.addColorStop("0.5","cyan");
gradient.addColorStop("1.0","tan");
// Fill with gradient
ctx.fillStyle=gradient;
ctx.fillText("w3school.com.cn",10,90);

</script>

</body>
</html>

猜你喜欢

转载自www.cnblogs.com/johnhery/p/9782303.html