Quick UI changes - what am I missing in jQuery width?

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?

+4
source share
1 answer

As far as I know, jQuery wraps the original javascript.

Do you understand that $ is made up in jQuery?

That is why, I think it makes sense that jQuery runs slower than the javascript source code.
Perhaps they did something first in .width () before the results get to you.

Try this link for reference.

Thank,

0
source

Source: https://habr.com/ru/post/1568445/


All Articles