Since formatting comments does not work, I will post the solution here
$(object).css({position: 'absolute',top: dy, left:dx}); // dy, dx - some coordinates $(object).css({position: 'relative'});
Does not work: the position of the element after changing to relative is different.
But when I saved the offset and set it again after changing to relative, the position will be the same:
$(object).css({position: 'absolute',top: dy, left:dx}); var x = $(object).offset().left; var y = $(object).offset().top; $(object).css({position: 'relative'}); $(object).offset({ top: y, left: x });
source share