I have this in my html (SVG about 500K):
<object type="image/svg+xml" data="/assets/images/test-diagram.svg" width="100%" height="100%" id="arm" class="svg-content"></object>
I am using a script on GitHub to create a viewport for SVG so that I can pan and zoom inside the viewport, but like GoogleMaps.
https://github.com/ariutta/svg-pan-zoom
So the loading order should be:
Unfortunately, the above code runs when the SVG is not fully loaded, resulting in errors.
I tried this but .load
doesn't seem to be intended for <object>
- debugger
never actually starts
$('#arm').load(function(){
debugger
var panZoomArm = svgPanZoom('#arm');
});
Could this tell me that the code only runs after 500k svg has been fully loaded?
The only way to keep this code safe is to make the SVG fully inline ... so, for example, hundreds of lines of code with no caching capability.
EDIT ----
Ok, I got it to work, but I'm confused.
This doesn't work (the debugger never starts):
$('#arm').load(function(){
debugger
var panZoomArm = svgPanZoom('#arm');
});
It works:
var arm = document.getElementById("arm");
arm.addEventListener('load', function(){
debugger
var panZoomArm = svgPanZoom('#arm');
});