<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>渐变文字</title>
</head>
<body>
<canvas id="can" width="500px" height="500px" style="border:1px solid #999"></canvas>
<script>
var c = document.querySelector("#can");
var ctx = c.getContext('2d');
ctx.font = "100px 微软雅黑";
// ctx.fillStyle="#f00";
// 设置线性渐变
var grd=ctx.createLinearGradient(0,0,c.width,0);
grd.addColorStop("0.3","yellow");
grd.addColorStop("0.7","blue");
grd.addColorStop("1.0","red");
// 应用渐变
ctx.fillStyle=grd;
ctx.fillText("你好,今天天气真好啊!!!",0,100,500);
</script>
</body>
</html>
05-24
683
07-12