Jquery: $ (window) .load () gets fired after css rendering?

I read this stackoverflow article:

Is $ (document) .ready () also CSS prepared?

The answer is clear: no, $(document).ready() does not guarantee full CSS rendering.

It made me wonder: what can I do to ensure that CSS fully rendered before some jQuery function (which relies on fully rendered CSS ) is executed? Is there an event that fires after CSS rendering? Solution $(window).load() ? $(window).load() seems to work fine for me, and seems to be what this developer recommends:

http://taitems.tumblr.com/post/780814952/document-ready-before-css-ready (this is our guess)

Right?

+4
source share
2 answers

I suggest loading CSS into the head before you invoke scripts, which ideally should be at the bottom of the HTML document. I used this and there has never been a case where the visible content is not visible.

+3
source

Just load CSS into the head before the scripts force it to load, but not display , before running the scripts. This is a problem, for example, for checking the positions of elements upon loading, which, when launched after loading CSS, but before displaying them, give the wrong answer.

If you have code that really depends on your CSS, using $(window).load(function () {...}) can save you a lot of headaches in the race.

+1
source

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


All Articles