Thursday 29 August 2013

Figures on svg canvas

Figures on svg canvas

I programmatically create several svg-images by JavaScript. Images are lines.
function create(elem) { //function for create svg
elem
var svg = "http://www.w3.org/2000/svg";
return document.createElementNS(svg, elem);
function set(elem, atrArr) { //function for set attributes svg elem
for (var i in atrArr) {
elem.setAttribute(i, atrArr[i])
}
}
function someFunc(valueWidth, valueHeight) {
var SVG = create('svg'); //canvas
var line = create('line'); //line
var width = valueWidth; //some value
var heigth = valueHeight; //some value
set(SVG, { //set canvas
version: '1.1',
width: width,
height: height
});
//set line
set(line, { x1: 0, x2: width, y1: 0, y2: height, style:
'stroke:rgb(0,0,0);stroke-width:1' });
SVG.style.position = 'absolute';
SVG.appendChild(line);
}
If height or width < 1, then line is drawn only in IE. Can I draw line in
other browsers without changing the size of the canvas?

No comments:

Post a Comment