|
|

楼主 |
发表于 2023-9-28 20:44
|
显示全部楼层
一楼示例代码:
- <style>
- #stage { border: 1px solid gray; }
- #stage > path { fill: none; stroke: steelblue; }
- #stage > circle { fill: red; cursor: pointer; }
- #stage > circle:nth-of-type(2) { fill: purple; }
- </style>
- <svg id="stage" width="400" height="400">
- <path id="cPath" d="M10 200 C10 10, 390 10, 390 200"></path>
- <circle id="c1" cx="10" cy="10" r="5"></circle>
- <circle id="c2" cx="390" cy="10" r="5"></circle>
- </svg>
- <div id="pathMsg"></div>
- <script>
- let movAr = [0,0];
- let setAttr = (ar) => ar.forEach((item) => item[0].setAttribute(item[1],item[2]));
- c1.onmousedown = () => movAr = [1,0];
- c2.onmousedown = () => movAr = [0,1];
- document.onmouseup = () => movAr = [0,0];
- pathMsg.innerText = '路径:' + cPath.getAttribute('d');
- stage.onmousemove = (e) => {
- if (movAr[0])
- setAttr([
- [c1,'cx',e.offsetX],
- [c1,'cy',e.offsetY],
- [cPath,'d',`M10 200 C${e.offsetX} ${e.offsetY}, ${c2.getAttribute('cx')} ${c2.getAttribute('cy')}, 390 200`],
- ]);
- if (movAr[1])
- setAttr([
- [c2,'cx',e.offsetX],
- [c2,'cy',e.offsetY],
- [cPath,'d',`M10 200 C${c1.getAttribute('cx')} ${c1.getAttribute('cy')}, ${e.offsetX} ${e.offsetY}, 390 200`],
- ]);
-
- if(movAr[0] || movAr[1]) pathMsg.innerText = '路径:' + cPath.getAttribute('d');
- };
- </script>
复制代码
|
评分
-
| 参与人数 1 | 威望 +50 |
金钱 +100 |
经验 +50 |
收起
理由
|
红影
| + 50 |
+ 100 |
+ 50 |
赞一个! |
查看全部评分
|