mask-type

mask-type 屬性指示在遮罩時,要為 <mask> 元素的內容使用哪種遮罩模式,是 alpha(透明度)還是 luminance(亮度)。

你可以將此屬性與以下 SVG 元素一起使用

注意: 此演示屬性有一個對應的 CSS 屬性:mask-type。當同時指定兩者時,CSS 屬性具有優先權。

示例

html
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
  <!-- Two identical masks other than the id and mask-type values -->
  <mask id="myMask1" mask-type="alpha">
    <rect
      fill="rgb(10% 10% 10% / 0.4)"
      x="0"
      y="0"
      width="100%"
      height="100%" />
    <circle fill="rgb(90% 90% 90% / 0.6)" cx="50" cy="50" r="35" />
  </mask>

  <mask id="myMask2" mask-type="luminance">
    <rect
      fill="rgb(10% 10% 10% / 0.4)"
      x="0"
      y="0"
      width="100%"
      height="100%" />
    <circle fill="rgb(90% 90% 90% / 0.6)" cx="50" cy="50" r="35" />
  </mask>

  <!-- The first rect is masked with an alpha mask -->
  <rect x="0" y="0" width="45" height="45" mask="url(#myMask1)" fill="red" />

  <!-- The last rect is masked with a luminance mask -->
  <rect x="55" y="0" width="45" height="45" mask="url(#myMask2)" fill="red" />
</svg>

mask

對於 <mask>mask-type 定義了遮罩元素的內容是作為亮度遮罩還是透明度遮罩進行處理。

alpha | luminance
預設值 luminance
可動畫的 alpha
alpha

此值指示應使用 <mask> 元素的 alpha 值;被遮罩物件的畫素與遮罩區域的不透明度相匹配,而不考慮遮罩顏色的亮度。

luminance

此值指示應使用 <mask> 元素的亮度值;被遮罩物件的不透明度取決於遮罩的透明度和亮度。luminance 遮罩的不透明度由遮罩的 RGBA 通道決定,使用公式 ((0.2125 * R) + (0.7154 * G) + (0.0721 * B)) * A

規範

此特性似乎未在任何規範中定義。

瀏覽器相容性

另見