I use this code to get the width of the document:
$(document).width()
But I noticed that my layout constantly breaks when I resize the window, I did some tests, and I found out that the speed of change is crucial. When I resize the window very slowly, the width value is correct. But when I quickly resize the window (in one step by 50%), the width is read from the previous state.
For comparison, I added
document.body.getBoundingClientRect()
The second approach gives me reliable reading all the time, no matter how fast the window change is.
Ok, I found what to use, but I would like to know what is wrong with the jQuery approach. So what am I missing here?
source
share