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


  1. <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">
  2. <!-- Generator: Sketch 53 (72520) - https://sketchapp.com -->
  3. <title>Group</title>
  4. <desc>Created with Sketch.</desc>
  5. <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
  6. <g id="Group" transform="translate(-3.000000, 0.000000)">
  7. <rect id="Rectangle" stroke="#979797" fill="#35D9F6" x="249.5" y="0.5" width="425" height="136"/>
  8. <text id="舞台" font-family="PingFangSC-Regular, PingFang SC" font-size="23" font-weight="normal" fill="#E35E1D">
  9. <tspan x="439" y="77">舞台</tspan>
  10. </text>
  11. <polyline points="20,20 40,25 60,40 80,120 120,140 200,180" style="fill:none;stroke:black;stroke-width:3"/>
  12. <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"/>
  13. <rect id="Rectangle" stroke="#979797" fill="#6250F3" x="262.5" y="332.5" width="405" height="138"/>
  14. <rect id="Rectangle" stroke="#979797" fill="#92E757" x="791.5" y="162.5" width="187" height="299"/>
  15. <text id="左边" font-family="PingFangSC-Regular, PingFang SC" font-size="23" font-weight="normal" fill="#61F849">
  16. <tspan x="56" y="312">左边</tspan>
  17. </text>
  18. <text id="后区-C" font-family="PingFangSC-Regular, PingFang SC" font-size="23" font-weight="normal" fill="#61F849">
  19. <tspan x="430" y="410">后区 C</tspan>
  20. </text>
  21. <text id="右区" font-family="PingFangSC-Regular, PingFang SC" font-size="23" font-weight="normal" fill="#F31FEF">
  22. <tspan x="862" y="320">右区</tspan>
  23. </text>
  24. </g>
  25. </g>
  26. </svg>

getStartPositionOfChar(text) & getEndPositionOfChar(text)

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

  1. temp1
  2. // <text id=​"后区-C" font-family=​"PingFangSC-Regular, PingFang SC" font-size=​"23" font-weight=​"normal" fill=​"#61F849">​…​</text>​
  3. temp1.getBBox();
  4. // SVGRect {x: 430, y: 386, width: 70.40625, height: 32}
  5. temp1.innerHTML;
  6. /*"
  7. <tspan xmlns="http://www.w3.org/2000/svg" x="430" y="410">后区 C</tspan>
  8. "
  9. */
  10. temp1.innerText
  11. // undefined
  12. temp1.textContent;
  13. /*
  14. "
  15. 后区 C
  16. "
  17. */
  18. temp1.getBBox();
  19. // SVGRect {x: 430, y: 386, width: 70.40625, height: 32}x: 430y: 386width: 70.40625height: 32__proto__: SVGRect
  20. temp1.getBoundingClientRect();
  21. // 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
  22. temp1.getAttribute(`fill`)
  23. // "#61F849"
  24. temp1.textLength;
  25. // 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
  26. temp1.getComputedTextLength();
  27. // 70.40298461914062
  28. temp1.getStartPositionOfChar(temp1);
  29. // SVGPoint {x: 430, y: 410}
  30. temp1.getEndPositionOfChar(temp1);
  31. // SVGPoint {x: 453, y: 410}


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


  1. temp1.getBBox();
  2. // SVGRect {x: 430, y: 386, width: 70.40625, height: 32}
  3. temp1.getCTM();
  4. // SVGMatrix {a: 1, b: 0, c: 0, d: 1, e: -3, …}a: 1b: 0c: 0d: 1e: -3f: 0__proto__: SVGMatrix
  5. temp1.childElementCount;
  6. // 1
  7. t
  8. emp1.firstElementChild
  9. // <tspan x=​"430" y=​"410">​后区 C​</tspan>​
  10. temp1.firstElementChild.x;
  11. // SVGAnimatedLengthList {baseVal: SVGLengthList, animVal: SVGLengthList}baseVal: SVGLengthList {0: SVGLength, length: 1, numberOfItems: 1}animVal: SVGLengthList {0: SVGLength, length: 1, numberOfItems: 1}__proto__: SVGAnimatedLengthList
  12. temp1.firstElementChild.getBBox();
  13. // SVGRect {x: 430, y: 386, width: 70.40625, height: 32}
  14. temp1.firstElementChild.getAttribute(`x`);
  15. // "430"
  16. temp1.firstElementChild.getAttribute(`y`);
  17. // "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. https://www.hutool.cn/ 糊涂

    一个Java基础工具类,对文件.流.加密解密.转码.正则.线程.XML等JDK方法进行封装,组成各种Util工具类,同时提供以下组件: 模块 介绍 hutool-aop JDK动态代理封装,提供非IO ...

  2. UserControl和CustomControl两者区别

    UserControl 将多个WPF控件(例如:TextBox,TextBlock,Button)进行组合成一个可复用的控件组: 由XAML和Code Behind代码组成: 不支持样式/模板重写: ...

  3. centos7+python3+selenium+chrome

    一.安装GUI图形化界面 (1)安装GUI图形化界面 yum groupinstall "GNOME Desktop" "Graphical Administration ...

  4. tarjan复习笔记 双连通分量,强连通分量

    声明:图自行参考割点和桥QVQ 双连通分量 如果一个无向连通图\(G=(V,E)\)中不存在割点(相对于这个图),则称它为点双连通图 如果一个无向连通图\(G=(V,E)\)中不存在割边(相对于这个图 ...

  5. JavaWeb——JSP内置对象request,response,重定向与转发 学习总结

    什么是JSP内置对象 九大内置对象 requestJSP内置对象 request对象常用方法 request练习 responseJSP内置对象 response练习 response与request ...

  6. Linux常用命令详解(第一章)(ls、man、pwd、cd、mkdir、echo、touch、cp、mv、rm、rmdir、)

    本章命令(共11个): 1 2 3 4 5 6 ls man pwd cd mkdir echo touch cp mv rm rmdir 1. " ls " 作用:列出指定目录下 ...

  7. C# 使用PictureBox实现图片按钮控件

    引言 我们有时候会在程序的文件夹里看见一些图标,而这些图标恰好是作为按钮的背景图片来使用的.鼠标指针在处于不同状态时,有"进入按钮"."按下左键"," ...

  8. CCF计算机软件能力认证试题练习:201912-5 魔数

    CCF计算机软件能力认证试题练习:201912-5 魔数 前置知识:BFS,线段树等 \(f(x) = (x\%A)\%B\) 这个函数值的和直接用线段树维护是不太行的(也可能是我不知道),后来想了很 ...

  9. KMP(算法描述)

    #include<iostream> using namespace std; const int N=10010,M=100010; int n,m; char p[N],s[M]; i ...

  10. c++虚函数、子类中调用父类方法

    全部 代码: 1 #include<stdio.h> 2 #include<string.h> 3 #include<iostream> 4 #include< ...