how to get svg text tspan x,y position value in js


<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="976px" height="471px" viewBox="0 0 976 471" version="1.1">
<!-- Generator: Sketch 53 (72520) - https://sketchapp.com -->
<title>Group</title>
<desc>Created with Sketch.</desc>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="Group" transform="translate(-3.000000, 0.000000)">
<rect id="Rectangle" stroke="#979797" fill="#35D9F6" x="249.5" y="0.5" width="425" height="136"/>
<text id="舞台" font-family="PingFangSC-Regular, PingFang SC" font-size="23" font-weight="normal" fill="#E35E1D">
<tspan x="439" y="77">舞台</tspan>
</text>
<polyline points="20,20 40,25 60,40 80,120 120,140 200,180" style="fill:none;stroke:black;stroke-width:3"/>
<polygon id="Polygon" stroke="#979797" fill="#F48787" points="79 216 154.133465 276.461013 125.435035 374.288987 32.5649651 374.288987 3.86653521 276.461013"/>
<rect id="Rectangle" stroke="#979797" fill="#6250F3" x="262.5" y="332.5" width="405" height="138"/>
<rect id="Rectangle" stroke="#979797" fill="#92E757" x="791.5" y="162.5" width="187" height="299"/>
<text id="左边" font-family="PingFangSC-Regular, PingFang SC" font-size="23" font-weight="normal" fill="#61F849">
<tspan x="56" y="312">左边</tspan>
</text>
<text id="后区-C" font-family="PingFangSC-Regular, PingFang SC" font-size="23" font-weight="normal" fill="#61F849">
<tspan x="430" y="410">后区 C</tspan>
</text>
<text id="右区" font-family="PingFangSC-Regular, PingFang SC" font-size="23" font-weight="normal" fill="#F31FEF">
<tspan x="862" y="320">右区</tspan>
</text>
</g>
</g>
</svg>

getStartPositionOfChar(text) & getEndPositionOfChar(text)



temp1.getStartPositionOfChar(temp1);
// SVGPoint {x: 430, y: 410} temp1.getEndPositionOfChar(temp1);
// SVGPoint {x: 453, y: 410}

temp1
// <text id=​"后区-C" font-family=​"PingFangSC-Regular, PingFang SC" font-size=​"23" font-weight=​"normal" fill=​"#61F849">​…​</text>​ temp1.getBBox();
// SVGRect {x: 430, y: 386, width: 70.40625, height: 32} temp1.innerHTML;
/*"
<tspan xmlns="http://www.w3.org/2000/svg" x="430" y="410">后区 C</tspan>
"
*/ temp1.innerText
// undefined temp1.textContent;
/*
"
后区 C
"
*/ temp1.getBBox();
// SVGRect {x: 430, y: 386, width: 70.40625, height: 32}x: 430y: 386width: 70.40625height: 32__proto__: SVGRect temp1.getBoundingClientRect();
// DOMRect {x: 427, y: 386, width: 70.40625, height: 32, top: 386, …}x: 427y: 386width: 70.40625height: 32top: 386right: 497.40625bottom: 418left: 427__proto__: DOMRect temp1.getAttribute(`fill`)
// "#61F849" temp1.textLength;
// SVGAnimatedLength {baseVal: SVGLength, animVal: SVGLength}baseVal: SVGLength {unitType: 0, value: 70.40298461914062, valueInSpecifiedUnits: 70.40298461914062, valueAsString: "70.403"}unitType: 0value: 70.40298461914062valueInSpecifiedUnits: 70.40298461914062valueAsString: "70.403"__proto__: SVGLengthanimVal: SVGLength {unitType: 0, value: 70.40298461914062, valueInSpecifiedUnits: 70.40298461914062, valueAsString: "70.403"}__proto__: SVGAnimatedLength temp1.getComputedTextLength();
// 70.40298461914062 temp1.getStartPositionOfChar(temp1);
// SVGPoint {x: 430, y: 410} temp1.getEndPositionOfChar(temp1);
// SVGPoint {x: 453, y: 410}


firstElementChild.getAttribute("x") & firstElementChild.getAttribute("y")


temp1.getBBox();
// SVGRect {x: 430, y: 386, width: 70.40625, height: 32} temp1.getCTM();
// SVGMatrix {a: 1, b: 0, c: 0, d: 1, e: -3, …}a: 1b: 0c: 0d: 1e: -3f: 0__proto__: SVGMatrix temp1.childElementCount;
// 1
t
emp1.firstElementChild
// <tspan x=​"430" y=​"410">​后区 C​</tspan>​ temp1.firstElementChild.x;
// SVGAnimatedLengthList {baseVal: SVGLengthList, animVal: SVGLengthList}baseVal: SVGLengthList {0: SVGLength, length: 1, numberOfItems: 1}animVal: SVGLengthList {0: SVGLength, length: 1, numberOfItems: 1}__proto__: SVGAnimatedLengthList temp1.firstElementChild.getBBox();
// SVGRect {x: 430, y: 386, width: 70.40625, height: 32} temp1.firstElementChild.getAttribute(`x`);
// "430" temp1.firstElementChild.getAttribute(`y`);
// "410"


http://tutorials.jenkov.com/svg/tspan-element.html

https://vanseodesign.com/web-design/svg-text-tspan-element/

https://stackoverflow.com/questions/20657512/svg-in-chrome-tspan-x-and-y-values-are-ignored


how to get svg text tspan x,y position value in js的更多相关文章

  1. svg text文字居中

    <text x="100" y="100" text-anchor="middle" dominant-baseline=" ...

  2. Sublime Text 3配置Minify压缩,格式化css,js,html,json,svg

    1.通过 Package Control 安装Minify 按 ctrl + shift + p   输入  Install Package 然后   输入Minify  按回车就可以安装啦 2.安装 ...

  3. SVG 文本

    该部分为四个主要部分: 1.  <text>和<tspan>标签详解 2.  文本水平垂直居中问题 3.  <textpath>让文本在指定路径上排列  4 ...

  4. SVG文本

    前面的话 本文将详细介绍SVG文本相关内容 位置属性 在一个SVG文档中,使用<text>元素来设置文本,<text>元素有x.y.dx.dy这四个位置属性 [x和y] 属性x ...

  5. svg文字与图像

    摘要: svg与canvas一样都可以将文本和图像放在画布中,制作出不一样的效果.下面是如何使用svg来渲染文本与图像. 简介: SVG的强大能力之一是它可以将文本控制到标准HTML页面不可能有的程度 ...

  6. SVG动画

    动画原理 SVG动画,就是元素的属性值关于时间的变化. 如下图来说,元素的某个属性值的起始值(from)到结束值(to)在一个时间段(duration)根据时间函数(timing-function)计 ...

  7. SVG的a链接

    SVG的a链接: <%@ page language="java" contentType="text/html; charset=UTF-8" page ...

  8. 深入浅出 SVG

    前言 据悉,8月18号将在广州举办中国第一届React开发者大会.今日早读文章由@Starrier翻译分享. 正文从这开始- SVG 是优秀且令人难以置信的强大图像格式.本教程通过简单地解释所有需要了 ...

  9. React生命周期及事件详解

    引用原文:http://blog.csdn.net/limm33/article/details/50942808 一.组件的详细说明和生命周期ComponentSpecs and Lifecycle ...

随机推荐

  1. synchronized的底层探索

    其实没看懂,但是提供了不同的思路,先记下 https://www.cnblogs.com/yuhangwang/p/11256476.html https://www.cnblogs.com/yuha ...

  2. office提示“应用程序无法正常启动(0xc0000142)。请单击确认关闭应用程序”

    打开word文档,突然弹出如下提示框: 网上查询,说应用程序无法正常启动(0xc0000142)的原因可能是缺少组件导致的.控制面板 - 时钟和区域 - 更改日期.时间或数字格式 - 管理 - 更改系 ...

  3. SQL操作数据——SQL组成,查询基础语法,where,Oracle常用函数等

    SQL组成 DML数据操作语言 DCL数据控制语言 DQL数据查询语言 DDL数据定义语言 查询基础语法 记录筛选 where 子句 记录筛选 where 子句 实例练习 实例练习 Select语句中 ...

  4. 12.su 命令与sudo 服务

     1.su 命令:解决切换用户身份的需求,使得当前用户在不退出登录的情况下,顺畅地切换到其他用户. 比如从root 管理员切换至普通用户: [root@Centos test]# id uid=0(r ...

  5. 源码剖析ThreadPoolExecutor线程池及阻塞队列

    本文章对ThreadPoolExecutor线程池的底层源码进行分析,线程池如何起到了线程复用.又是如何进行维护我们的线程任务的呢?我们直接进入正题: 首先我们看一下ThreadPoolExecuto ...

  6. java面试必备String详解

    引言 众所周知在java里面除了8种基本数据类型的话,还有一种特殊的类型String,这个类型是我们每天搬砖都基本上要使用它. String 类型可能是 Java 中应用最频繁的引用类型,但它的性能问 ...

  7. Linux lsblk和df命令区别

    lsblk 查看的是block device,也就是逻辑磁盘大小. df查看的是file system, 也就是文件系统层的磁盘大小

  8. Codeforces Round #627 (Div. 3) A - Yet Another Tetris Problem(逻辑)

    题意 : 有n个高度,可以使任一高度加二任意次,问最终n个高度可否相同. 思路: 因为添加的2x1的方块不可旋转,只需考虑所有高度是否为同一奇偶性即可. #include <bits/stdc+ ...

  9. Codeforces Round #691 (Div. 2) C. Row GCD (数学)

    题意:给你两个数组\(a\)和\(b\),对于\(j=1,...,m\),找出\(a_1+b_j,...,a_n+b_j\)的\(gcd\). 题解:我们很容易的得出\(gcd\)的一个性质:\(gc ...

  10. ElasticSearch入门到筋痛

    1. 什么是ES ES中文网:https://www.elastic.co/guide/cn/elasticsearch/guide/current/index.html ES:是一款基于Lucene ...