Skip to content

SVG and javascript

jackdarker edited this page Aug 14, 2021 · 6 revisions

My plan was to dynamical load vector-graphics and combine them to an image just like you can stack multiple images in css-background.
With the svg-<use> command it should be possible to combine the separatly loaded svg into one scene.

But I run into several problems here:

  • svg can be loaded via <img> but then you cannot access each component of svg for re-styling
  • you can either inline-embedd an SVG in html or use to load dynamical from a path
  • first one is ugly to edit (copy paste from svg-file)
  • both are creating a visible image; but I just want to get the svg loaded to be able to them
  • I CANNOT access contentDocument (opposed to the many examples out there) from the loaded svg inside because of cross-origin-blocking for local files !

So my current workaround is like this:

  • create a js-function that builds a svg-html for each picture (copy paste svg-code from svg-file into function)
  • those function are called and the svg-html is printed inside a <div> that is hidden
  • the scene can now <use> those svg-html because it exists in the html-document

Todo: how to load a svg-file from disk and append its content to <symbol>-container of scene-svg?

Clone this wiki locally