Code: Select all
<html>
<body>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="92.364212mm"
height="49.764038mm"
viewBox="0 0 327.27477 176.32927"
id="svg2"
version="1.1"
inkscape:version="0.91 r13725"
sodipodi:docname="drawing1.svg"
onload="startAnimation(evt)">
<defs
id="defs4" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.98994949"
inkscape:cx="66.995504"
inkscape:cy="-99.774488"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="1920"
inkscape:window-height="984"
inkscape:window-x="0"
inkscape:window-y="25"
inkscape:window-maximized="1"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0" />
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-193.46898,-119.94397)">
<path
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:30, 30;stroke-dashoffset:50;stroke-opacity:1"
d="M 518.20826,125.04217 C 197.9899,97.768049 195.96959,293.73764 195.96959,293.73764"
id="path4136"
inkscape:connector-curvature="0" />
</g>
<script type="text/ecmascript">
var timerFunction = null;
var svgRoot =null;
function startAnimation(evt) {
svgRoot = evt.target;
if(timerFunction == null) {
timerFunction = setInterval(animate, 20);
}
}
function animate() {
var curva = svgRoot.getElementById("path4136");
var x = curva.style['stroke-dashoffset'];
var len = curva.getTotalLength();
var p = curva.getPointAtLength(100);
var newX = 2 + parseInt(x);
if(newX >= 60) {
newX = 0;
}
curva.style['stroke-dashoffset'] = newX;
}
</script>
</svg>
</body>
</html>
as you can see the <script> element is a child of the <svg> element.
I wonder if is possible to embed the script into a standalone svg file and then load it from an html as an object or (better) an image.
This because I need to upload animated image into forums or wiki pages, so the html pages are dinamically created and then all animation details (comprise the use of javascript library like jquery or snapsvg) has to be embedded exclusively into the svg file.
best regards
Max