JSFiddle - React, Tailwind, and code Playground
HTML
<div class="div1"></div>
<div class="div2"></div>
CSS
div {
position: relative;
width: 50px;
height: 50px;
background-image: url(http://www.unityninjas.com/wp-content/uploads/2015/02/all_sprite_64_2.png);
}
JavaScript
var parentCenter = {
x: 100,
y: 100
};
var radius = 100;
var duration = 50000;
$('.div1').animate({
left: 0
}, {
progress: function (animation, progress) {
var xPos = Math.round((parentCenter.x + Math.cos(progress * Math.PI * 2 + Math.PI) * radius) * 1000) / 1000;
var yPos = Math.round((parentCenter.y + Math.sin(progress * Math.PI * 2 + Math.PI) * radius) * 1000) / 1000;
$(this).css({
left: xPos,
top: yPos
});
},
duration: duration
});
$('.div2').animate({
left: 0
}, {
progress: function (animation, progress) {
var xPos = Math.round((parentCenter.x + Math.cos(progress * Math.PI * 2) * radius) * 1000) / 1000;
var yPos = Math.round((parentCenter.y + Math.sin(progress * Math.PI * 2) * radius) * 1000) / 1000;
$(this).css({
transform: 'translateX(' + (xPos) + 'px) translateY(' + (yPos) + 'px)'
});
},
duration: duration
});