I have the following code that I apply on click:
$("#search").click(function()
{
if (searchForth)
{
animateRotate(45,"#search");
searchForth = false;
}
else
{
animateRotate(-45,"#search");
searchForth = true;
}
});
And the function being called:
function animateRotate(d,element)
{
var elem = $(element);
$({deg: 0}).animate({deg: d},{
duration: 600,
step: function(now)
{
elem.css({
transform: "rotate(" + now + "deg)"
});
}
});
}
When the function gets called, the element rotates 45 degrees from the default position, which is what I want. However, when I click on the element again, the function applies a rotation of -45 degrees, but it does so from the default position of the element instead of the position the element was left in from the previous rotation. Why is that and how can I fix it so the second animation 'picks off' from the final position of the first animation?