|
|

楼主 |
发表于 2023-9-30 11:28
|
显示全部楼层
左边是 ellipse 标签绘制的椭圆,右边是 path 标签根据 ellipse 相关属性值绘制的椭圆。完整代码:
- <style>
- .mysvg { border: 1px solid gray; fill: none; stroke: steelblue; }
- </style>
- <svg class="mysvg" width="200" height="200">
- <ellipse id="Ellipse" cx="100" cy="100" rx="90" ry="60"></ellipse>
- </svg>
- <svg class="mysvg" width="200" height="200">
- <path id="ePath" d="M0 0 H200"></path>
- </svg>
- <div id="pathMsg"></div>
- <script>
- let createPath = (ele) => {
- let cx = 1 * ele.getAttribute('cx'),
- cy = 1 * ele.getAttribute('cy'),
- rx = 1 * ele.getAttribute('rx'),
- ry = 1 * ele.getAttribute('ry');
- return `
- M${cx-rx} ${cy}
- A${rx} ${ry} 0 1 1 ${(cx + rx)} ${cy}
- A${rx} ${ry} 0 1 1 ${cx-rx} ${cy}
- `;
- };
- ePath.setAttribute('d',createPath(Ellipse));
- pathMsg.innerText = createPath(Ellipse);
- </script>
复制代码
|
|