当前位置:网站首页>svg标签中利用<polygon/>循环数组绘制多边形
svg标签中利用<polygon/>循环数组绘制多边形
2022-04-23 03:06:00 【张小欢ㄦ~】
1、将所有循环的坐标存在数组里,因为我们要画矩形,所以每个数组里面的坐标点应该有八个,几循环数组的形式:【 [x1 y1,x2 y2,x3 y3,x4 y4],[x1 y1,x2 y2,x3 y3,x4 y4],[x1 y1,x2 y2,x3 y3,x4 y4]......】;
2、代码: 数组 ratioPositionArr即为上面形式;
//将后端返回来的数据做处理:将每个数组里面的坐标等比例放大缩小,再存在一个新数组中。
locationsPosition(newVal, oldVal) {
this.activeIfSvg = ''
this.ratioPositionArr = []
// console.log(77, newVal)
// this.ratioPositionArr=newVal
const itemArr = []
this.eryArr = []
// console.log('eryArr', this.ratioWidth)
newVal.forEach((item, index) => {
item.forEach(itemevery => {
this.eryArr.push(itemevery / this.ratioWidth)
})
itemArr.push(this.eryArr)
this.eryArr = []
})
// console.log('itemArr', itemArr)
this.ratioPositionArr = itemArr
// console.log('99',this.ratioPositionArr)
},
<div
id="svgbox"
class="svgbox"
style="border: 2px solid white"
ref="svgcanvas"
@mousedown="move"
>
<svg
class="svgelement"
style="width: 100%; height: 100%; border: 1px solid white"
ref="svgcanvas"
>
<polygon
v-for="(item, index) in ratioPositionArr"
:points="item"
:key="index"
:class="activeIfSvg === index ? 'activeIfSvg' : ''"
@click="getClickSvg(index)"
></polygon>
</svg>
</div>
3、最终效果:蓝色边框即为 svg---polygon--points 根据数组中的坐标画出的多边形!

版权声明
本文为[张小欢ㄦ~]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_51196135/article/details/124345579
边栏推荐
- tf. keras. layers. Embedding function
- JS learning notes
- How to deploy a website with only a server and no domain name?
- 利用栈的回溯来解决“文件的最长绝对路径”问题
- Introduction to ACM [TSP problem]
- ASP.NET和ASP.NETCore多环境配置对比
- 宁德时代地位不保?
- [software testing] understand the basic knowledge of software testing
- c#语法糖模式匹配【switch 表达式】
- Binary tree
猜你喜欢

tf. keras. layers. Conv? D function

Opencv combines multiple pictures into video

Array and collection types passed by openfeign parameters

Deep q-network (dqn)

Cloud computing learning 1 - openstack cloud computing installation and deployment steps with pictures and texts (Xiandian 2.2)
![How to use C language to realize [guessing numbers game]](/img/8c/052dcb0ce64ee1713bebb1340248e6.png)
How to use C language to realize [guessing numbers game]
![Introduction to ACM [TSP problem]](/img/9f/4e3592542d989b2fbb6d82f7f2fbd2.png)
Introduction to ACM [TSP problem]

Summary of interface automation interview questions for software testing

荐读 | 分享交易员的书单,向名家请教交易之道,交易精彩无比

再战leetcode (290.单词规律)
随机推荐
求二叉树的叶子结点个数
MYSQL03_ SQL overview, rules and specifications, basic select statements, display table structure
Openfeign timeout setting
[format] simple output (2)
Passing object type parameters through openfeign
Simple example of using redis in PHP
Thoughts on the 2022 national network security competition of the national secondary vocational group (only one idea for myself) - network security competition questions (9)
Openfeign details show
Q-Learning & Sarsa
Cherno_ Game engine series tutorial (5): 101~
C# 读写二进制文件
.Net Core 限流控制-AspNetCoreRateLimit
如果通过 C# 实现对象的深复制 ?
C# 11 的这个新特性,我愿称之最强!
最通俗易懂的依赖注入之服务容器与作用域
Opencv fills the rectangle with a transparent color
建立与遍历二叉树
Blazor University (12)组件 — 组件生命周期
Xamarin效果第二十一篇之GIS中可扩展浮动操作按钮
腾讯视频VIP会员,周卡特价9元!腾讯官方直充,会员立即生效!
https://www.textin.com/experience/text_recognize_3d1