Open QuatschSalat opened 11 years ago
You need to assign a size to your container div:
<div id="svgfile" style="width: 500px; height: 400px;"></div>
OK, cool. This has solved my problem. Thank you. Is there a way to set the height of the container depending on the height of the SVG graphic?
Did you solve that problem? I have the same problem. Only in webkit based browsers, in Firefox it works fine. Assigning a fixed height solves it, but I need it in a variable size.
I was trying to find the height and width of the externally loaded svg. My container div is completely blank. I added the callback handler "svgLoaded" to the original call:
$("#containerDiv").svg({loadURL: 'yourExternalSVGFile.svg', changeSize: true, onLoad: svgLoaded});
I then went to the DOM & got the first child of the container Div, using the function "getFirstChild" below to weed out text nodes:
function svgLoaded(e) {
var theContainerDiv = document.getElementById("containerDiv");
var theSVG = getFirstChild(theContainerDiv);
var theWidth = theSVG.width.baseVal.valueAsString;
var theHeight = theSVG.height.baseVal.valueAsString;
// I set the container's dimensions to the child's dimensions - not necessary
//theContainerDiv.style.width = theWidth + "px";
//theContainerDiv.style.height = theHeight + "px";
}
function getFirstChild(el){
var firstChild = el.firstChild;
while(firstChild != null && firstChild.nodeType == 3){ // skip TextNodes
firstChild = firstChild.nextSibling;
}
return firstChild;
}
[These internals of these functions could have been done using more JQuery-style calls.]
For my use, this is in a template that gets reused. I have to "clean house" in the div at load time to make this work. I am also going to going to center & scale the child up to the div's dimensions, subject to internal padding restraints.
Hi,
I'm trying to load the content of a SVG file into a div element. Although the content is loaded, the height of the SVG is always "null". Here is the HTML code I'm using:
The file "lion.svg" is located in the same directory as the HTML file. I've already tried it with different versions of jQuery. Without success.
The generated content looks like this:
If I set a value of 500 for the height in the web inspector, my SVG graphic is displayed. Here's the error message in Safari:
Error: Invalid value for <svg> attribute height="null"
container.clientHeight
in "jquery.svg.js" line 104 is always zero.