We got 3 points: start , end and mail .

The email image moves in a curved line from the start and end points, this is done using jQuery animation.
Now the next step is to make the mail image rotate during the animation. Thus, at the start and end point, it will rotate 0 degrees, but during animation, it should rotate, referring to the animation path. (see image)
What I tried:
Jsfiddle
var $start = $('#start');
var $end = $('#end');
var $mail = $('#mail');
var startPos = $start.position();
var endPos = $end.Position();
var getAngle = function(currX, currY, endX, endY) {
var angle = Math.atan2(currX - endX, currY - endY) * (180 / Math.PI);
if (angle < 0) {
angle = Math.abs(angle);
} else {
angle = 360 - angle;
}
return angle;
};
var getMailAngle = function() {
var currPos = $mail.position();
var endPos = $end.position();
return getAngle(currPos.left, currPos.top, endPos.left, endPos.top);
};
$mail.animate({top: endPos.top, left: endPos.left}, {
specialEasing: {left: "easeInSine", top: "linear"},
step: function() {
var angle = getMailAngle();
$(this).css('transform', 'rotate(' + angle + 'deg'));
}
});
But the code above is incorrect, when starting / ending the angle is not turned up, I have very little experience in geometry mathematics, so I really appreciate the help for rotating calculations.