diff options
| author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
|---|---|---|
| committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
| commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
| tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/svg/element/clippath | |
| parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
| download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip | |
initial commit
Diffstat (limited to 'files/zh-cn/web/svg/element/clippath')
| -rw-r--r-- | files/zh-cn/web/svg/element/clippath/index.html | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/files/zh-cn/web/svg/element/clippath/index.html b/files/zh-cn/web/svg/element/clippath/index.html new file mode 100644 index 0000000000..4922bd1e93 --- /dev/null +++ b/files/zh-cn/web/svg/element/clippath/index.html @@ -0,0 +1,115 @@ +--- +title: clipPath +slug: Web/SVG/Element/clipPath +tags: + - Clip + - SVG + - 元素 + - 参考 +translation_of: Web/SVG/Element/clipPath +--- +<div>{{SVGRef}}</div> + +<p><a href="/zh-CN/docs/Web/SVG">SVG</a> 元素 <strong><code><clipPath></code></strong> 定义一条剪切路径,可作为其他元素的 {{SVGAttr("clip-path")}} 属性的值。</p> + +<p>剪切路径限制了图形的可见范围。从概念上来说,如果图形超出了当前剪切路径所包围的区域,那么超出部分将不会绘制。</p> + +<div id="Example"> +<div class="hidden"> +<pre class="brush: css">html,body,svg { height:100% }</pre> +</div> + +<pre class="brush: html"><svg viewBox="0 0 100 100"> + <clipPath id="myClip"> + <!-- + 圆圈外的所有东西都会被裁剪掉,因此不可见。 + --> + <circle cx="40" cy="35" r="35" /> + </clipPath> + + <!-- 作为引用元素(英文原文:<code>for reference</code>)的黑色心形 --> + <path id="heart" d="M10,30 A20,20,0,0,1,50,30 A20,20,0,0,1,90,30 Q90,60,50,90 Q10,60,10,30 Z" /> + + <!-- + 和上述黑色心形形状相同的红色心形,剪切路径是上面定义的圆; + 红色心形只有在圆内的部分可见。 + --> + <use clip-path="url(#myClip)" xlink:href="#heart" fill="red" /> +</svg></pre> + +<pre class="brush: css">/* 如果浏览器支持几何属性 r,可以加一点 css */ + +@keyframes openYourHeart {from {r: 0} to {r: 60px}} + +#myClip circle { + animation: openYourHeart 15s infinite; +}</pre> + +<p>{{EmbedLiveSample('Example', 100, 100)}}</p> +</div> + +<p>从概念上讲,剪切路径等于给引用元素设置了一个自定义的可视区域。因此,它虽然会影响一个元素的绘制,但不会影响这个元素本身的几何形状,比如被剪切元素(通过 {{SVGAttr("clip-path")}} 属性引用了 <code><clipPath></code> 的元素及其子元素)的包围盒和没有被剪切时相同。</p> + +<p>默认情况下,{{cssxref("pointer-events")}} 不会在被剪切掉的区域(不可见的区域)内触发。举个例子,如果一个半径为10的圆形被剪切成半径为5的圆形,那么这个圆在半径为5以外的区域不会收到“click”事件。</p> + +<h2 id="属性">属性</h2> + +<dl> + <dt>{{SVGAttr("clipPathUnits")}}</dt> + <dd>为 <code><clipPath></code> 元素的内容定义坐标系。<br> + <small><em>Value type</em>: <code>userSpaceOnUse</code>|<code>objectBoundingBox</code> ; <em>Default value</em>: <code>userSpaceOnUse</code>; <em>Animatable</em>: <strong>yes</strong></small></dd> +</dl> + +<h3 id="全局属性">全局属性</h3> + +<dl> + <dt><a href="https://developer.mozilla.org/docs/Web/SVG/Attribute/Core">Core Attributes</a></dt> + <dd><small>Most notably: {{SVGAttr('id')}}</small></dd> + <dt><a href="https://developer.mozilla.org/docs/Web/SVG/Attribute/Styling">Styling Attributes</a></dt> + <dd><small>{{SVGAttr('class')}}, {{SVGAttr('style')}}</small></dd> + <dt><a href="https://developer.mozilla.org/docs/Web/SVG/Attribute/Conditional_Processing">Conditional Processing Attributes</a></dt> + <dd><small>Most notably: {{SVGAttr('requiredExtensions')}}, {{SVGAttr('systemLanguage')}}</small></dd> + <dt><a href="https://developer.mozilla.org/docs/Web/SVG/Attribute/Presentation">Presentation Attributes</a></dt> + <dd><small>Most notably: {{SVGAttr('clip-path')}}, {{SVGAttr('clip-rule')}}, {{SVGAttr('color')}}, {{SVGAttr('display')}}, {{SVGAttr('fill')}}, {{SVGAttr('fill-opacity')}}, {{SVGAttr('fill-rule')}}, {{SVGAttr('filter')}}, {{SVGAttr('mask')}}, {{SVGAttr('opacity')}}, {{SVGAttr('shape-rendering')}}, {{SVGAttr('stroke')}}, {{SVGAttr('stroke-dasharray')}}, {{SVGAttr('stroke-dashoffset')}}, {{SVGAttr('stroke-linecap')}}, {{SVGAttr('stroke-linejoin')}}, {{SVGAttr('stroke-miterlimit')}}, {{SVGAttr('stroke-opacity')}}, {{SVGAttr('stroke-width')}}, {{SVGAttr("transform")}}, {{SVGAttr('vector-effect')}}, {{SVGAttr('visibility')}}</small></dd> +</dl> + +<h2 id="用法">用法</h2> + +<p>{{svginfo}}</p> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">规范</th> + <th scope="col">状态</th> + <th scope="col">备注</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName("CSS Masks", "#ClipPathElement", "<clipPath>")}}</td> + <td>{{Spec2("CSS Masks")}}</td> + <td></td> + </tr> + <tr> + <td>{{SpecName("SVG1.1", "masking.html#EstablishingANewClippingPath", "<clipPath>")}}</td> + <td>{{Spec2("SVG1.1")}}</td> + <td>Initial definition</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + + + +<p>{{Compat("svg.elements.clipPath")}}</p> + +<h2 id="相关内容">相关内容</h2> + +<ul> + <li>Other clipping and masking SVG elements: {{SVGElement("mask")}}</li> + <li>Some CSS properties: {{cssxref("clip-path")}}, {{cssxref("pointer-events")}}</li> +</ul> |
