简体   繁体   中英

Partially transparent (opacity) HTML5 Canvas drawings

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.

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

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

Examples:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM