0
I created a circle to rotate 45 degrees every time I click the arrow, either right or left.
For this I am using CSS and jQuery. (FIDDLE NEXT)
I did the following function spin(direction)
so that it encompassed any of the senses clicked on the arrow by the users, so much so that I came across the question of discovering the degrees of an element and knowing only in format matrix
, format by which javascript returns and searching, I adapted a function to convert matrix -> graus
. The code works perfectly!
The point is, when I click many times, either right or left, after a certain number of clicks, the circle screws into the rotation, and always hangs with the "come and go" movement, increasing and decreasing the degrees, and I’m not able to break this vicious cycle of the event. I have provided above the fiddle so that you can simulate what I am playing here!
Below follows 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;
}
}
really a much simpler approach! When I saw the conversion to Matrix, I tried to solve it more before.
– João Vitor
could you show me where the limitation is in this conversion function? It is possible to change by removing this limitation
– João Vitor