javascript - Using jquery html() method to get width of dynamic text needs timeout -
I'm trying to use a technique that I've seen elsewhere so that quickly with any dynamic text Insert a DOM node. However, to get the width of a div, however, after the html () call, the result of the width () method gives me, I think, unchanged width later I can get width with formatted text. What does it give here? Is there a delay in painting? Is there a better way to do this, like with inline styles or some things? Or am I completely losing a concept?
var htmlStr = "& lt; span id = 'userFeedbackText' class = 'user-feedback-text' & gt; + F +" & lt; / Span & gt; "; _feedbackEl.html (htmlStr); _feedbackEl.show (); console.log ($ (" # userFeedbackText ") outerWidth ().); // 238 window.setTimeout (function () {console. Edit: OK, well I hide the CSS visibility setting:
I'm facing the problem, so that the problem can be solved but I still want to know the underlying mechanism in this specific example. Thanks
EDIT2: I have snatched the app in empty disorder.It seems because the dynamic text is a fonts from Google fonts, which is remotely referenced. So, I'm guessing here, the first width has been shaky, then the browser has a little bit to present the text in the font. It takes time, so there is a change in width in Chrome or Safari (sporadic) on Mac Mavricks here, Belal is also sporadic, fire on Firefox for Mac first time
Comments
Post a Comment