user1401379
user1401379

Reputation:

Add Class While Loading

Is there a way to use AddClass in jQuery to add a class while a page and the assets are loading?

For example you could add a class of loading to the body tag.

You can't use the DOM ready function can you?

Upvotes: 1

Views: 537

Answers (2)

matsko
matsko

Reputation: 22183

This may give you some ideas of how to go about doing this.

https://plus.google.com/116910304844117268718/posts/UkaymyuTzaF

What I usually do is setup a attribute and then have JS turn it off when all the assets are ready. In CSS then I define a loading animation on areas of the body where I want them to appear.

Upvotes: 0

MrOBrian
MrOBrian

Reputation: 2189

Putting my comment as an answer so this question can be marked as answered...

Set the loading class in the html and then use .removeClass to remove it once the document has finished loading.

Upvotes: 3

Related Questions