直接撸代码:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>js控制SVG缩放</title> </head> <body> <svg id="svg" style="background-color: #FAFAFA;"> <g id="svgPanel"> <g id="grid"></g> <defs> <path id="path1" d="M300,200 a1,1 0 0,0 100,0" /> </defs> <text x="10" y="100" style="fill:green;"> <textPath xlink:href="#path1">啦啦啦啦啦啦啦啦啦啦</textPath> </text> </g> </svg> <button οnclick="zoom(1.1)">放大</button> <button οnclick="zoom(0.9)">缩小</button>