当前位置:网站首页>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
边栏推荐
- Source code interpretation of Flink index parameters (read quantity, sent quantity, sent bytes, received bytes, etc.)
- Thoughts on the 2022 national network security competition of the national secondary vocational group (only one idea for myself) - network security competition questions (9)
- 最通俗易懂的依赖注入之生命周期
- 对.NET未来的一点感悟
- What kind of experience is it to prepare for a month to participate in ACM?
- TP5 multi conditional where query (using PHP variables)
- Deep q-network (dqn)
- AC & A2C & A3C
- [Euler plan question 13] sum of large numbers
- Laravel's own paging query
猜你喜欢
ASP.NET 6 中间件系列 - 条件中间件
MYSQL04_ Exercises corresponding to arithmetic, logic, bit, operator and operator
腾讯视频VIP会员,周卡特价9元!腾讯官方直充,会员立即生效!
Ningde's position in the times is not guaranteed?
Introduction to ACM [TSP problem]
Some problems encountered in setting Django pure interface, channel and MySQL on the pagoda panel
利用栈的回溯来解决“文件的最长绝对路径”问题
树莓派开发笔记(十二):入手研华ADVANTECH工控树莓派UNO-220套件(一):介绍和运行系统
由于3²+4²=5²,所以称‘3,4,5‘为勾股数,求n(包括n)以内所有勾股数数组。
How to use C language to realize [guessing numbers game]
随机推荐
tf. keras. layers. Density function
Source Generator实战
微软是如何解决 PC 端程序多开问题的
[software testing] understand the basic knowledge of software testing
Tips in MATLAB
Vs code setting line feed
[ncnn] - the meaning of - 23300 in param
Introduction and use of openfeign component
Service avalanche effect
Gavl021, gavl281, AC220V to 5v200ma small volume non isolated chip scheme
TP5 email (2020-05-27)
Reverse a linked list < difficulty coefficient >
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
Numpy append function
Ningde's position in the times is not guaranteed?
荐读 | 分享交易员的书单,向名家请教交易之道,交易精彩无比
Blazor University (11)组件 — 替换子组件的属性
ASP.NET 6 中间件系列 - 条件中间件
Summary of software test interview questions
LNMP MySQL allows remote access