Some JS operations for SVG DOM

Source: Internet
Author: User

This is the first instance, which says how to create a new svg, add elements, save svgDocument, viewing svgThe following will be the addition of some common elements: (JS, but basically the same as in Java, the class name is slightly different) Circle
var svgns = "Http://www.w3.org/2000/svg";



Svgdocument = evt.target.ownerDocument;


Shape.setattributens (NULL, "Cy", 25);
Shape.setattributens (NULL, "R", 20);


}
Ellipse
var svgns = "Http://www.w3.org/2000/svg
function Makeshape (EVT)

if (window.svgdocument = = null)

var shape = Svgdocument.createelementns (svgns, "ellipse");






}
Line
var svgns = "Http://www.w3.org/2000/svg










}
Path
var svgns = "Http://www.w3.org/2000/svg




var shape = Svgdocument.createelementns (svgns, "path




}
Polygon
var svgns = "Http://www.w3.org/2000/svg









}
Polyline
var svgns = "Http://www.w3.org/2000/svg









}
Rectangle
var svgns = "Http://www.w3.org/2000/svg




var shape = Svgdocument.createelementns (svgns, "rect "






}
Rounded Rectangle
var svgns = "Http://www.w3.org/2000/svg




var shape = Svgdocument.createelementns (svgns, "rect "








}
Use
var svgns = "Http://www.w3.org/2000/svg";
var xlinkns = "Http://www.w3.org/1999/xlink";
function Makeshape (EVT)
{
if (window.svgdocument = = null)
Svgdocument = evt.target.ownerDocument;
var svgroot = svgdocument.documentelement;
var defs = Svgdocument.createelementns (svgns, "defs");
Varrect= Svgdocument.createelementns (Svgns, "rect");
rect. Setattributens (NULL, "id", "rect");
rect. Setattributens (NULL, "width", 15);
rect. Setattributens (NULL, "height", 15);
rect. Setattributens (null, "style", "Fill:green");
Defs.appendchild (rect);
var use1 = Svgdocument.createelementns (svgns, "use");
Use1.setattributens (NULL, "X", 5);
Use1.setattributens (null, "Y", 5);
Use1.setattributens (Xlinkns, "Xlink:href", "#rect");
Use2 = Svgdocument.createelementns (svgns, "use");
Use2.setattributens (NULL, "X", 30);
Use2.setattributens (null, "Y", 30);
Use2.setattributens (Xlinkns, "Xlink:href", "#rect Svgroot.appendchild (defs);
Svgroot.appendchild (USE1);
Svgroot.appendchild (USE2);
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.