【问题标题】:how to show correctly svg mask in chrome如何在 chrome 中正确显示 svg 掩码
【发布时间】:2018-03-19 18:12:05
【问题描述】:

我想在文本上屏蔽 svg 以显示数据,但在 chrome 中无法正确显示 我用面具创建了svg,它在firefox中完美地工作,但在chrome中不起作用 我想在文本上应用蒙版以在滚动中透明显示文本

HTML:

    <div class="content">
    <div class="xx">
    <p>some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text</p>
    </div>
       <svg>
        <defs>
          <linearGradient id="grad1" x1="0%" y1="0%" x2="0%" y2="100%">
            <stop offset="0%" style="stop-color:rgb(0,0,0);stop-opacity:1" />
            <stop offset="40%" style="stop-color:rgb(255,255,255);stop-opacity:1" />
            <stop offset="60%" style="stop-color:rgb(255,255,255);stop-opacity:1" />
            <stop offset="100%" style="stop-color:rgb(0,0,0);stop-opacity:1" />
          </linearGradient>

          <mask id="masking" maskUnits="objectBoundingBox" maskContentUnits="objectBoundingBox">
             <rect width="1" height="1" fill="url(#grad1)"/>
          </mask>
       </defs>
     </svg>
    </div>

CSS:

    <style>
    .xx {
      mask: url(#masking);
    }
    body{
      background: red
    }

    .content{
      width:300px;
      height:200px;
    }
    .xx{
      height:200px;
      overflow-y:scroll;
    }.xx {
      mask: url(#masking);
    }
    body{
      background: red
    }

    .content{
      width:300px;
      height:200px;
    }
    .xx{
      height:200px;
      overflow-y:scroll;
    }
    </style>

jsfiddle Link

【问题讨论】:

    标签: google-chrome svg mask


    【解决方案1】:

    Chrome 不支持 HTML 元素上的 mask。但是它确实支持mask-image

    See the caniuse site for more information.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-03
      • 2014-11-25
      • 2016-06-04
      • 2021-04-09
      • 2013-05-16
      • 1970-01-01
      • 2021-12-11
      • 2011-04-24
      相关资源
      最近更新 更多