I created a circle to be rotated 45 degrees every time I click the arrow, either right or left.
For this done, I'm using CSS and jQuery. ( SEGUE FIDDLE )
I made the following function spin(direction)
to include any of the directions clicked on the arrow by the users, so much so that I came across the issue of discovering the degrees of an element and knowing only in matrix
format, format by which javascript return and search, I have adapted a function for matrix -> graus
conversion. The code works perfectly!
The point is, when I click many times, either right or left, after a certain number of clicks, the circle twists in the rotation, and always hangs with the "come and go" movement, increasing and decreasing degrees , and I can not break this vicious cycle of the event. I made the fiddle above so that you can simulate what I am interpreting here!
Below is my code:
$("#turn-spinner-right").click(function(){
var sentido = 'right';
spin(sentido);
});
$("#turn-spinner-left").click(function(){
var sentido = 'left';
spin(sentido);
});
function spin(direction){
var transform = $(".spinner").css("transform");
console.log('MATRIX: '+transform);
var angle = convertMatrixToAngle(transform);
console.log(angle);
switch(direction){
case 'left':
if($(".spinner").css( "transform" ) == 'none'){
$(".spinner").css("transform","rotate(-45deg)");
} else {
var newAngle = angle-45;
console.log('novo angulo:'+newAngle);
$(".spinner").css("transform","rotate("+newAngle+"deg)");
}
break;
case 'right':
if($(".spinner").css( "transform" ) == 'none'){
$(".spinner").css("transform","rotate(45deg)");
} else {
var newAngle = angle+45;
console.log('novo angulo:'+newAngle);
$(".spinner").css("transform","rotate("+newAngle+"deg)");
}
break;
}
}