最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Partially transparent (opacity) HTML5 Canvas drawings - Stack Overflow

programmeradmin0浏览0评论

Is it possible to create partially transparent elements on the fly in canvas? Currently I'm setting the whole canvas element's opacity in CSS, but I want to some elements to be more visible then others.

Nothing I've found so far indicates that this is possible.

Is it possible to create partially transparent elements on the fly in canvas? Currently I'm setting the whole canvas element's opacity in CSS, but I want to some elements to be more visible then others.

Nothing I've found so far indicates that this is possible.

Share Improve this question edited Jul 11, 2010 at 19:06 Josh K asked Jul 11, 2010 at 16:57 Josh KJosh K 28.9k20 gold badges88 silver badges132 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

Simply use rgba(r, g, b, a) (where a is your alpha transparency from 0 (pletely transparent) to 1 (pletely opaque):

myContext.fillStyle = "rgba(0, 0, 0, 0.5)";

Examples:

  • https://developer.mozilla/samples/canvas-tutorial/4_4_canvas_rgba.html
  • https://developer.mozilla/en/drawing_graphics_with_canvas
发布评论

评论列表(0)

  1. 暂无评论