评论资讯 [ 总 428 则 ]
·悄然 - 2024-12-24 19:55
·小希 - 2024-12-24 19:51
·飞飞 - 2024-12-24 19:45
·悄然 - 2024-12-24 19:41
·了了 - 2024-12-18 21:32
·悄然 - 2024-12-17 15:19
·悄然 - 2024-12-15 15:12
·悄然 - 2024-12-9 12:32
·飞飞 - 2024-12-9 12:31
·小希 - 2024-12-7 11:50
·小希 - 2024-12-24 19:51
·飞飞 - 2024-12-24 19:45
·悄然 - 2024-12-24 19:41
·了了 - 2024-12-18 21:32
·悄然 - 2024-12-17 15:19
·悄然 - 2024-12-15 15:12
·悄然 - 2024-12-9 12:32
·飞飞 - 2024-12-9 12:31
·小希 - 2024-12-7 11:50
友情链接
网站统计
svg : rect to path 演示
【说明】当 rect 设置了圆角,简单的 rect 转 path 机制变得无比复杂,需要一一处理四个角。以下代码考虑到了常规的情形:
<style> .mysvg { border: 1px solid gray; fill: none; stroke: steelblue; } </style> <svg class="mysvg" width="200" height="200"> <rect id="Rect" x="10" y="10" width="100" height="100" rx="8" ry="18"></rect> </svg> <svg class="mysvg" width="200" height="200"> <path id="cPath" d="M10 100 H190"></path> </svg> <div id="pathMsg"></div> <script> let createPath = (eRect) => { let x = 1 * eRect.getAttribute('x'), y = 1 * eRect.getAttribute('y'), w = 1* eRect.getAttribute('width'), h = 1* eRect.getAttribute('height'), rx = 1 * eRect.getAttribute('rx') || 0, ry = 1 * eRect.getAttribute('ry') || 0; console.log(rx,ry); return (rx === 0 || ry === 0) ? `M${x} ${y} h${w} v${h} h-${w} v-${h}` : `M${x} ${y + ry} a${rx} ${ry} 0 0 1 ${rx} -${ry} h${w - rx * 2} a${rx} ${ry} 0 0 1 ${rx} ${ry} v${h - ry * 2} a${rx} ${ry} 0 0 1 -${rx} ${ry} h-${w - rx * 2} a${rx} ${ry} 0 0 1 -${rx} -${ry} v-${h - ry * 2}`; }; cPath.setAttribute('d',createPath(Rect)); pathMsg.innerText = createPath(Rect); </script>
前一篇: svg : ellipse to path 演示
下一篇: 生成svg星形图案和路径
发表评论:
评论列表 [0条]