Changing color for fillText() on HTML5

I am trying to change the color for each line of my messages on canvas, but no success so far. I have tried creating variable for each one of them, but still no luck. any help would be appreciated. function initiate(){ var elem = document.getElementById("canvas"); canvas = elem.getContext("2d"); addEventListener("mousemove", animation); canvas.shadowColor = "rgba(0, 0, 0, 0.5)"; canvas.shadowOffsetX = 4; canvas.shadowOffsetY = 4; canvas.shadowBlur = 5; canvas.font = "bold 24px verdana, sans-serif "; var welcomeMessage ="Welcome to the store!"; canvas.textAlign = "start"; canvas.textBaseline = "bottom"; canvas.fillText(welcomeMessage, 400, 50); canvas.font = "bold 14px verdana, sans-serif"; var message2 = "Your favorite store for videos games and latest DVDs!"; canvas.textAlign = "start"; canvas.textBaseline = "bottom"; canvas.fillText(message2, 400, 100); canvas.font = "bold 12px verdana, sans-serif"; canvas.textAlign = "start"; canvas.textBaseline = "bottom"; // Create gradient //var gradient=canvas.createLinearGradient(0,0,c.width,0); //gradient.addColorStop("0","magenta"); //gradient.addColorStop("0.5","blue"); //gradient.addColorStop("1.0","red"); //canvas.fillStyle = gradient; canvas.fillText("

以上就是Changing color for fillText() on HTML5 的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏