【问题标题】:View the inverse region of clip-path查看剪辑路径的反向区域
【发布时间】:2017-05-22 07:18:01
【问题描述】:

这是一个简单的小提琴,在一个矩形内显​​示一个圆形区域 https://jsfiddle.net/3v6yhf0m/

svg {
  border: 3px dashed #999;
}
svg > rect:hover {
  fill: green;
}
<svg width="120" height="120" xmlns="http://www.w3.org/2000/svg">
  <defs>
    <clipPath id="myClip">
      <circle cx="30" cy="30" r="20"/>
    </clipPath>
  </defs>

  <rect x="10" y="10" width="100" height="100" fill="blue"
      clip-path="url(#myClip)"/>
</svg>

但我想使用剪辑路径查看位于圆外的矩形区域 https://jsfiddle.net/yhbeevya/

svg {
  border: 3px dashed #999;background-color:blue;fill:blue;
}
svg > rect:hover {
  fill: green;
}
<svg width="120" height="120" xmlns="http://www.w3.org/2000/svg">
  <defs>
    <clipPath id="myClip">
      <circle cx="30" cy="30" r="20"/>
    </clipPath>
  </defs>

  <rect x="10" y="10" width="100" height="100" fill="white"
      clip-path="url(#myClip)"/>
</svg>

请分享你的想法

【问题讨论】:

    标签: html svg clip


    【解决方案1】:

    改用面具。蒙版的黑色部分显示背景,白色显示形状本身。

    svg {
      border: 3px dashed #999;background-color:blue;fill:blue;
    }
    svg > rect:hover {
      fill: green;
    }
    <svg width="120" height="120" xmlns="http://www.w3.org/2000/svg">
      <defs>
        <mask id="myMask">
          <rect width="100%" height="100%" fill="white"/>
          <circle cx="30" cy="30" r="20" fill="black"/>
        </mask>
      </defs>
    
      <rect x="10" y="10" width="100" height="100" fill="white"
          mask="url(#myMask)"/>
    </svg>

    【讨论】:

    • 谢谢,我试试这个
    猜你喜欢
    • 2018-07-22
    • 2023-04-08
    • 2019-11-11
    • 1970-01-01
    • 2011-03-02
    • 2019-06-07
    • 2016-09-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多