当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


SVG markerHeight属性用法及代码示例


markerHeight属性指示<marker>根据其所保存的视口的高度,该视口根据saveAspectRatio和viewBox属性显示。仅<marker>元素正在使用此属性。

用法:

markerrHeight = "length-percentage" | "number"

属性值:markerHeight属性接受上面提到和下面描述的值。

  • length-percentage:它指示标记的相对高度或绝对高度。
  • 数:它以markerUnits属性定义的单位指示标记的高度。

注意:markerHeight属性的默认值为3。

范例1:以下示例说明了markerHeight属性的用法。



HTML

<!DOCTYPE html> 
<html> 
  
    <body> 
        <h1 style="color:green;  
            margin-left:10px;"> 
            GeeksforGeeks 
        </h1> 
  
        <svg viewBox="0 15 1220 520" 
             xmlns="http://www.w3.org/2000/svg"> 
            <defs> 
                <marker id="geek"
                    viewBox="0 0 10 10"
                    refX="1" refY="5"
                    markerUnits="strokeWidth"
                    markerWidth="8"
                    markerHeight="8"
                    orient="auto"> 
                   <path d="M 0 0 L 10 5 L 0 10 z" 
                    fill="#008000"/> 
                </marker> 
            </defs> 
  
            <polyline points="20, 20 40, 25 60, 
                    40 80, 120 120, 140 200, 180" 
                    style="fill:none;stroke:green; 
                    stroke-width:5"  
                    marker-end="url(#geek)"/> 
          </svg> 
    </body> 
     
</html>

输出:

范例2:

HTML

<!DOCTYPE html> 
<html> 
  
    <body> 
        <h1 style="color:green;  
            margin-left:10px;"> 
            GeeksforGeeks 
        </h1> 
  
        <svg viewBox="0 15 1220 520" 
             xmlns="http://www.w3.org/2000/svg"> 
            <defs> 
                <marker id="geek"
                    viewBox="0 0 10 10"
                    refX="1" refY="5"
                    markerUnits="strokeWidth"
                    markerWidth="8"
                    markerHeight="8"
                    orient="auto"> 
                   <path d="M 0 0 L 10 5 L 0 10 z" 
                    fill="#008000"/> 
                </marker> 
            </defs> 
  
            <polyline points="100, 105 180, 
                    20 100, 17 50, 100" 
                    stroke="green" 
                    stroke-width="5" 
                    fill ="none"
                    marker-end="url(#geek)"/> 
          </svg> 
    </body> 
     
</html>

输出:




相关用法


注:本文由纯净天空筛选整理自thacker_shahid大神的英文原创作品 SVG markerHeight Attribute。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。