Note that there are some explanatory texts on larger screens.

plurals
  1. POElements position changing after setting position to absolute
    primarykey
    data
    text
    <p>I have run into a pretty weird problem that I have managed to fix, but in a disgusting way.</p> <p>I have the following working code that grabs the left and top of the element (using MooTools). It then uses <code>setStyles</code> to copy these measured coordinates into the style attribute. This works pretty well.</p> <p>But as soon as I set the position to absolute the values in the code above it appear to change.</p> <p><strong>Works but horrible:</strong></p> <pre><code>var Sortable = new Class({ initialize: function(element, container) { // Store the element and its settings this.element = element; this.size = element.getSize(); this.position = element.getPosition(container); // Set the position element.setStyles({ left: this.position.x, top: this.position.y }); setTimeout(this.goAbsolute.bind(this), 0); }, goAbsolute: function() { this.element.setStyle('position', 'absolute'); } }); </code></pre> <p>As you can see, I am using a timeout to separate the left / top setting and the position setting. The following code does not work.</p> <pre><code>var Sortable = new Class({ initialize: function(element, container) { // Store the element and its settings this.element = element; this.size = element.getSize(); this.position = element.getPosition(container); // Set the position element.setStyles({ left: this.position.x, top: this.position.y, position: 'absolute' }); } }); </code></pre> <p>So, we can use this.</p> <pre><code>this.size = element.getSize(); </code></pre> <p>And <code>size.x</code> will equal 100 for example. Then with this added line.</p> <pre><code>this.size = element.getSize(); element.setStyle('position', 'absolute'); </code></pre> <p><code>size.x</code> will now equal 0. Even though it was set to absolute after.</p> <p>I have tried cloning the object and its values.</p> <p>I have tried putting them all out of scope of each other.</p> <p>Nothing seems to work.</p> <p>Does anyone know of a way to do a similar fix but without <code>setTimeout</code>? Or is that the best way.</p> <p>I have tried to explain my problem as best as I can but it is a bit of a strange one. So comment with any questions.</p> <p>Thank you for any suggestions you may have.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload