Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert absolute position to relative

Is it possible to change DIV position from absolute to relative (and from relative to absolute)? DIV should remain on same place.

like image 511
John Avatar asked Mar 30 '10 14:03

John


1 Answers

Because formatting in comments is not work I will publish solution here

$(object).css({position: 'absolute',top: dy, left:dx});
// dy, dx - some coordinates
$(object).css({position: 'relative'});

Does not work: element position after changing to relative is different.

But when I stored offset and set it again after changing to relative, position is 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 }); 
like image 142
John Avatar answered Oct 02 '22 01:10

John