Rotate Square
by C C
HTML
<svg width="200px" height="200px">
<g transform="translate(100,100)" id="myImage">
<rect id="mySquare" x="-10" y="-10" width="20" height="20" fill="blue" />
</g>
</svg>
<input id="speed" type="text" value="10" />
<button id="zoom" onclick="startAnimation();">Start</button>
JavaScript
var squareShape;
var myTimer;
var speed;
function startAnimation() {
squareShape = document.getElementById("mySquare");
speed = document.getElementById("speed"); // missing in original code
squareShape.currentTheta = 0;
myTimer = setInterval(animateImage, speed.value); // not an option, but is the right answer.
animateImage();
}
function animateImage() {
squareShape.setAttribute("transform", "rotate(" + squareShape.currentTheta + ")");
squareShape.currentTheta += 0.1;
}