svg dom沿路径绘制文本
2013-12-30 20:38
393 查看
<!DOCTYPE
html>
<html>
<head>
<meta charset="utf-8">
<title>svg
dom沿路径绘制文本</title>
<style>
#text{
border: 1px solid red;
width: 380px;
height: 200px;
}
</style>
<script>
function
createText(){
var
root=document.getElementByIdx_x("text");
var
SVG="http://www.w3.org/2000/svg";
var
XLINK="http://www.w3.org/1999/xlink";
var
svg=document_createElement_xNS(SVG,"svg");
svg.setAttribute("width","380");
svg.setAttribute("height","200");
//创建我们的defs元素
var
defs=document_createElement_xNS(SVG,"defs");
svg.a(defs);
//创建我们的path元素
var
circlePath=document_createElement_xNS(SVG,"path");
circlePath.setAttribute("d","M10,50"+
"C10,50
50,0 100,50"+
"C100,50
150,100,190,50"+
"M10,150"+
"C10,150
50,100 100,150"+
"C100,150
150,200 190,150"
);
circlePath.setAttribute("id","circlePath");
//创建我们的g元素
var
g=document_createElement_xNS(SVG,"g");
g.setAttribute("fill","dodgerblue");
g.setAttribute("font-size","15");
g.setAttribute("transform","translate(100,0)");
//创建我们的text元素
var
text=document_createElement_xNS(SVG,"text");
//创建我们的textPath元素
var
textPath=document_createElement_xNS(SVG,"textPath");
textPath.setAttributeNS(XLINK,"href","#circlePath");
textPath.textContent="SVG与文本:使用textPath进行字符串显示实例";
var
circle=document_createElement_xNS(SVG,"use");
circle.setAttributeNS(XLINK,"href","#circlePath");
circle.setAttribute("fill","none");
circle.setAttribute("stroke","blue");
defs.a(circlePath);
text.a(textPath);
g.a(text);
svg.a(g);
root.a(svg);
}
</script>
</head>
<body
onload="createText();">
<h3>svg
dom沿路径绘制文本</h3>
<div
id="text"></div>
</body>
</html>
相关文章推荐
- svg dom绘制文本
- SVG Dom绘制线段
- svg dom绘制折线
- SVG Dom绘制矩形
- svg dom绘制五角星
- SVG Dom绘制圆形
- SVG DOM通过path绘制五角星
- SVG Dom绘制椭圆
- SVG DOM方式实现g元素的变形
- svg沿路径绘制文本
- SVG Dom使用g元素
- iOS下载文件,保存路径.&nbsp;防止…
- 最短路径问题 hdu 3790
- Gtk-WARNING&nbsp;**:&nbsp;无法在模块路径中…
- C# 绘制曲线(一)
- 完美解决qt(4.8.4) 中文路径问题
- matlab读取文本之 textread
- org.w3c.dom(java&nbsp;dom)解析XML文档
- java 中 路径的获取 (转)
- 数据库访问大段文本数据&nbsp;&nbsp;(myqsl&nbsp;…