November 14, 201016 yr Hi guys, Just playing around with a site based on a 6-column grid layout. What I'd like to do is to have the site quickly fade in (from black) after ALL the elements have completely loaded. At the moment, there's a twitter feed in place that seems to take the longest to load but I can't seem to come up with any javascript that will only kick in after the twitter api has been accessed and read. I'm using a fair bit of jquery and I was thinking the code might look a little bit like this: $(window).ready(function() { $('body').css({'display' : 'none'}).fadeIn(3000); }; Or maybe: $(document).ready(function() { $('body').hide().fadeIn(5000); }); The problem with those is that they don't wait until the twitter api has been accessed and loaded into the page. Anyone got any ideas on how I might be able to do it?? Maybe it's not possible!
November 14, 201016 yr Have you tried putting it onto a timer? You could put it onto 5 seconds (for example) then let it fade in? Have the body as display:none, and when it fades in, it is displayed? Just a suggestion, as im not sure how it would check everything has loaded
November 14, 201016 yr Author Have you tried putting it onto a timer? You could put it onto 5 seconds (for example) then let it fade in? Have the body as display:none, and when it fades in, it is displayed? Just a suggestion, as im not sure how it would check everything has loaded Yeah, I've pretty much tried that but i still doesn't wait until the twitter api has done its thing. I thought of just delaying it by an amount that would allow it to have definitely loaded (10 secs or something to be safe) but it seems like a really crappy way of doing it - there must be a slicker method. Cheers though.
November 14, 201016 yr Hmm well if the time for the twitter feed is much more than the other stuff, maybe it's working having a little animated .gif that stays in the twitter feed until its loaded. This way your not compromising the rest of your site loading time because of the twitter feed. Or, When the main page has loaded, get it to fade in, and if the twitter feed hasnt loaded, get that to fade in when it eventually does. Other than this I have no idea
November 15, 201016 yr Author Thanks mate - worked it out (eventually). For anyone who's interested, I did this: $(document).ready(function() { $('body').css({ opacity: 0 }); }); $(window).load(function () { $('body').animate({ opacity: 1 }, 2000, function() { // Animation complete. }); } The first function kicks in immediately, while the 2nd one waits patiently for ALL elements to fully load. I'm sure that's not the most elegant way of doing it, but it's worked for me.
Create an account or sign in to comment