1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style>
html, body{
height: 100%;
margin: 0px;
padding: 0px
}
</style>
<script type="text/ecmascript">
function addRotateTransform(target_id, speed, direction) {
var loaderConteneur = document.createElement("div");
loaderConteneur.id = 'loader');
document.body.appendChild(loaderConteneur);
var svgns="http://www.w3.org/2000/svg";
var svg=document.createElementNS(svgns, "svg");
svg.setAttribute('width', '200px');
svg.setAttribute('height', '200px');
svg.setAttribute('x', '0px');
svg.setAttribute('y', '0px');
document.getElementById("loader").appendChild(svg);
var xlinkns="http://www.w3.org/1999/xlink";
var element_to_rotate = document.createElementNS(svgns, "use");
element_to_rotate.setAttributeNS(xlinkns, 'xlink:href', '#loaderSimple');
element_to_rotate.setAttributeNS(null, 'x', 0);
element_to_rotate.setAttributeNS(null, 'y', 0);
element_to_rotate.setAttributeNS(null, 'stroke-width', 2);
element_to_rotate.setAttributeNS(null, 'stroke', "#006699");
element_to_rotate.setAttributeNS(null, 'fill', 'none');
svg.appendChild(element_to_rotate)
var my_transform = document.createElementNS(svgns, "animateTransform");
var bb = element_to_rotate.getBBox();
var cx = bb.x + bb.width/2;
var cy = bb.y + bb.height/2;
// alert(cx+"\n"+cy+"\n"+bb.width);
my_transform.setAttributeNS(xlinkns, 'xlink:href', '#loaderSimple');
my_transform.setAttributeNS(null, "attributeName", "transform");
my_transform.setAttributeNS(null, "attributeType", "XML");
my_transform.setAttributeNS(null, "type", "rotate");
my_transform.setAttributeNS(null, "dur", speed + "s"); // en seconde
my_transform.setAttributeNS(null, "repeatCount", "indefinite");
my_transform.setAttributeNS(null, "from", "0 "+cx+" "+cy);
my_transform.setAttributeNS(null, "to", 360*direction+" "+cx+" "+cy);
// my_transform.setAttributeNS(null, 'transform', 'scale(.5)');
element_to_rotate.appendChild(my_transform);
my_transform.beginElement();
}
</script>
</head>
<body>
<div style="display:none; "><svg version="1.1" id="svg1" xmlns="http://www.w3.org/2000/svg" display="inline" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="21px" height="21px" viewBox="88.733 12.014 21 21">
<defs>
<path id="loaderSimple" stroke-linecap="round" stroke-linejoin="round" d="M74.592,6.486c16.437,8.369,27.695,25.448,27.695,45.157c0,27.971-22.675,50.644-50.644,50.644C23.674,102.287,1,79.614,1,51.644C1,23.674,23.674,1,51.644,1c3.004,0,5.946,0.262,8.807,0.763"/>
</defs>
</svg></div>
</body>
<script type="text/javascript">addRotateTransform('loaderSimple', 2, 1); </script>
</html> |
Partager