I’m currently working on a project with sencha. In this project i have a rotating ‘wheeloffortune’ wheel that spins to a certain part of the wheel to get your bonus.
I did this before with some javascript where i created intervals to switch the css class of the div but that didn’t work well.
I now want to do it with css3 animation for which i have the following css:
@-webkit-keyframes rotater {
from {
-webkit-transform: rotate(0deg);
}
to {
-webkit-transform: rotate(3600deg);
}
}
.css3-rotaterFull {
-webkit-animation-name: rotater;
-webkit-animation-iteration-count: 1;
-webkit-animation-timing-function:ease-out;
-webkit-animation-duration: 15s;
}
But i need to spin it to a certain angle which is variable. therefor i need to be able to set the
to {
-webkit-transform: rotate(3600deg);
}
part to a variable number of degrees before i add the class to the div
Any idea on how to do this ?
Use the CSSOM: http://dev.w3.org/csswg/cssom/
Once you know what the end degree is, pass it to this function. It will grab the last stylesheet in your document, create a rule with the dynamic degree plugged in, and then inserts the rule into the stylesheet and adds the proper class to your element so it uses the animation.
The webkitAnimationEnd listener is there to remove the rule from the stylesheet once the animation finishes so the rules don’t continuously build up and also removes the webkitAnimationEnd listener itself so it doesn’t interfere with the next spin.