vendredi 1 juillet 2016

How to force synchronous relayout in javascript

I have javascript code that changes some css to move things around and then calls getBoundingClientRect (or .offset using jquery, makes no difference). I'm getting results that make very little sense. I suspect I'm getting old values, while the relayout happens on a background thread. If I split my code into two functions and have the first call the second via setTimeout, everything works fine (except during the timeout interval).

I've found lots of stuff online about things that might force relayouts, written from a "avoid these; they're slow" perspective. What I'm doing is on those lists.

But what I need is a way to definitely force a synchronous relayout, and I can't find that. Is there one?

(This is in both Firefox and Chrome, in case that matters)

Aucun commentaire:

Enregistrer un commentaire