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

规范

此特性似乎未在任何规范中定义。

浏览器兼容性

另见