Convert absolute position to relative

2024/2/27 9:09:53

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

Answer

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 }); 
http://en.ppmy.cn/q/41294.html

Related Q&A

Render Highcharts after user updated labels

I am trying to create a chart builder. I have a user inputs for Title and location of the legend. I want a user to type in a title and when the click off (blur) the chart to be updated with what they…

Accessing the height of div in javascript

I have a div :cssdiv { width: 200px; height:auto }markup<div contenteditable="true"> Text is editable </div>Now what should i do to access the height ( numeric value ) of the abov…

Best way to deal with very large Long numbers in Ajax?

Javascript represents all numbers as double-precision floating-point. This means it loses precision when dealing with numbers at the very highest end of the 64 bit Java Long datatype -- anything after…

Why do you access Symbol.iterator via brackets?

If I created an array, for instance, var array=[1,2,3,4]; to return an iterator I would do var iterator = array[Symbol.iterator](); I dont understand why you access the Symbol.iterator property through…

Points drawn in the onload event of the SVG element are NOT being displayed when rendered

Im working on drawing an SVG grid using Javascript. Ive managed to get the axis drawn, as well as my quadrant labels. However Ive run into an issue adding my dynamic points.Im trying to draw the points…

What is the use case for break Identifier in JavaScript?

the spec goesBreakStatement : break ;break [no LineTerminator here] Identifier ;then it goesThe program contains a break statement with the optional Identifier, where Identifier does not appear in th…

How to redefine the + operator on Arrays in JavaScript?

Assuming points are represented using JavaScript Array as [x,y], how could I define the + operator on points such that:[1,2] + [5,10] == [6,12]

Creating array with spread syntax

Here is a JavaScript arrow function I found in a React book: const createArray = (length) => [...Array(length)];Why not simply return a new array? const createArray = (length) => Array(length);I…

How do I access promise callback value outside of the function?

It is to my understanding that callback functions are asynchronous and cannot return a value like regular functions. Upon reading about promises, I thought I grasped a good understanding about them, th…

How to pass string and component as prop?

I can pass something like this fine:<CardTitle title={this.props.post.title} subtitle={<Link to={this.props.post.author}>{this.props.post.author}</Link> } />But I need to pass both a …