当前位置:网站首页>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
边栏推荐
- Publish to NPM?
- The whole network is the most complete. How to do interface automation test? Proficient in interface automation test details
- 一套关于 内存对齐 的C#面试题,做错的人很多!
- How to deploy a website with only a server and no domain name?
- Traversal of l2-006 tree (middle and later order determination binary tree & sequence traversal)
- Passing object type parameters through openfeign
- 最通俗易懂的依赖注入之服务容器与作用域
- Opencv combines multiple pictures into video
- Laravel's own paging query
- Notes sur le développement de la tarte aux framboises (XII): commencer à étudier la suite UNO - 220 de la tarte aux framboises de contrôle industriel advantech (i): Introduction et fonctionnement du s
猜你喜欢

树莓派开发笔记(十二):入手研华ADVANTECH工控树莓派UNO-220套件(一):介绍和运行系统

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

再战leetcode (290.单词规律)

TP5 customization in extend directory succeeded and failed. Return information

Thoughts on the 2022 national network security competition of the national secondary vocational group (only one idea for myself) - network security competition questions (7)

微软是如何解决 PC 端程序多开问题的
![How to use C language to realize [guessing numbers game]](/img/8c/052dcb0ce64ee1713bebb1340248e6.png)
How to use C language to realize [guessing numbers game]

Development notes of raspberry pie (12): start Advantech industrial control raspberry pie uno-220 Kit (I): introduction and operation of the system

【新版发布】ComponentOne 新增 .NET 6 和 Blazor 平台控件支持

Blazor University (12)组件 — 组件生命周期
随机推荐
腾讯视频VIP会员,周卡特价9元!腾讯官方直充,会员立即生效!
Opencv fills the rectangle with a transparent color
Plug in for vscode
C#语法糖空合并运算符【??】和空合并赋值运算符【 ??=】
Numpy stack function
C# 11 对 ref 和 struct 的改进
It turns out that PID was born in the struggle between Lao wangtou and Lao sky
Redis Cluster集群,主节点故障,主从切换后ip变化,客户端需要处理不
SQL statement - DDL
How to count the number of all files in a directory under win10 system
.NET7之MiniAPI(特别篇):.NET7 Preview3
The whole network is the most complete. How to do interface automation test? Proficient in interface automation test details
[software testing] understand the basic knowledge of software testing
树莓派开发笔记(十二):入手研华ADVANTECH工控树莓派UNO-220套件(一):介绍和运行系统
利用栈的回溯来解决“文件的最长绝对路径”问题
Introduction to ACM [inclusion exclusion theorem]
Use split to solve the "most common words" problem
tf. keras. layers. Density function
准备一个月去参加ACM,是一种什么体验?
Restart redis
https://www.textin.com/experience/text_recognize_3d1