let str = info;
let c = document.createElement("canvas");
document.body.appendChild.c;
let ctx = c.getContext("2d");
ctx.font = "14px Arial";
let gradient = ctx.createLinearGradient(0, 0, c.width, 0);
gradient.addColorStop("1", "rgba(0,0,0,0.1)");
ctx.fillStyle = gradient;
ctx.setTransform(0.9, -0.4, 0.5, 1, 5, 60);
ctx.fillText(str, 0, 40);
let imgsrc = c.toDataURL("image/png");
let a = document.getElementById('box');
a.style.background = "url(" + imgsrc + ") 0/30%,url(" + imgsrc + ") 25%/30%";
本文来自博客园,作者:ljyyjj,转载请注明原文链接:https://www.cnblogs.com/ljyyjj/p/15878209.html