HTML canvas globalAlpha attribute

Definition and Usage

globalAlpha The attribute sets or returns the current transparency value of the drawing (alpha or transparency).

globalAlpha The attribute value must be between 0.0and (completely transparent) with 1.0The number between (opaque) and

Example

First, draw a red rectangle, then set the transparency (globalAlpha) to 0.2, and then draw a green and a blue rectangle:

Your browser does not support the canvas tag.

JavaScript:

var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.fillStyle="red";
ctx.fillRect(20,20,75,50);
// تعديل الشفافية
ctx.globalAlpha=0.2;
ctx.fillStyle="blue";
ctx.fillRect(50,50,75,50);
ctx.fillStyle="green";
ctx.fillRect(80,80,75,50);

جرب بنفسك

النحو

سياق.globalAlpha=رقم;

قيمة الخاصية

القيمة الوصف
رقم قيمة الشفافية. يجب أن تكون بين 0.0 (شفاف تمامًا) و 1.0 (غير شفاف).

تفاصيل التقنية

القيمة الافتراضية: 1.0

دعم المتصفحات

الرقم في الجدول يوضح إصدار المتصفح الأول الذي يدعم هذه الخاصية بشكل كامل.

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
4.0 9.0 3.6 4.0 10.1

ملاحظة:Internet Explorer 8 وأحدث إصداراته لا يدعم عنصر <canvas>.