If I change some properties of some dom element in a function using javascript does the browser recalculate new position of elements immediately, before the function will be finished? That is, if I made one element invisible like obj.style.display = 'none'
and read in the same functions properties of another element will they be recalculated?
Asked
Active
Viewed 20 times
0

Роман Коптев
- 1,555
- 1
- 13
- 35
-
They will recalculated once the function is finished. – super11 May 25 '16 at 15:01
-
Everything is calculated when Javascript returns to the main event loop. – Barmar May 25 '16 at 15:02
1 Answers
2
The answer is slightly more perverse than that. DOM updates in modern browsers are cached before being flushed at a certain interval... BUT, by inquiring into the DOM's state, you force the browser to perform the reflow there and then. It's part of the expected behaviour.
See an explanation here
So, if you want to defer the reflow, maybe get whatever computed values you require first. Otherwise, you should be ok. However, as it's part of a "standard", you may find implementations differ or stray.

Community
- 1
- 1

Jeff Watkins
- 6,343
- 16
- 19