Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Just wanted to add my experience here, though the question's old: The consensus above seems to be that jQuery's rounding is effectively just as good as an unrounded calculation -- but that doesn't seem to be the case in something I've been doing.</p> <p>My element has a fluid width, generally, but content that changes dynamically via AJAX. Before switching the content, I temporarily lock the dimensions of the element so my layout doesn't bounce around during the transition. I've found that using jQuery like this:</p> <pre><code>$element.width($element.width()); </code></pre> <p>is causing some funniness, like there are sub-pixel differences between the actual width and the calculated width. (Specifically, I will see a word jump from one line of text to another, indicating the the width has been changed, not just locked.) From another question -- <a href="https://stackoverflow.com/questions/11907514/getting-the-actual-floating-point-width-of-an-element">Getting the actual, floating-point width of an element</a> -- I found out that <code>window.getComputedStyle(element).width</code> will return an unrounded calculation. So I changed the above code to something like</p> <pre><code>var e = document.getElementById('element'); $('#element').width(window.getComputedStyle(e).width); </code></pre> <p>And with THAT code -- <em>no funny bouncing!</em> That experience seems to suggest that the unrounded value actually <em>does</em> matter to the browser, right? (In my case, Chrome Version 26.0.1410.65.)</p>
 

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