RSS Feed MattJura.com
Register Login

jQuery tip avoiding loading delay

If like me you include your java scripts and

$(document).ready(function() {
});

at the bottom of the page, than very often when using jQuery slide show (for example cycle plugin or similar), you will notice that the images load first and show up on the page before being hidden via script located at the bottom of the page.

There is a simple workaround that I use to make sure that this does not happen.

In this example we have three images/banners that I want to rotate using jQuery. The "slideshow" class is my hook for the jQuery plugin and I have added "jqhidden" class which I use first
to hide and than to show the div once script is loaded.

<div class="slideshow jqhidden">
<a href="#"><img src="banner1.jpg"></a>
<a href="#"><img src="banner2.jpg"></a>
<a href="#"><img src="banner3.jpg"></a>
</div>

Using CSS I hide the div, the style sheet is loaded first so the images do not show.

.jqhidden {
visibility:hidden;
}

Than at the bottom of the page I include a function which changes the visibility from "hidden" to "visible".

<script type="text/javascript">
$(document).ready(function() {
// cycle plugin script
$('.slideshow').cycle({
fx: 'scrollRight' ,
speed: 1000 ,
timeout:5000
});
// show the div with slide show
$('.jqhidden').css('visibility','visible');
});
</script>


I use this method with not only slide shows and galleries but for other visual elements for example tabs.

Comments

There are currently no comments, be the first to post one.

Post Comment

Name (required)

Email (required)

Website

CAPTCHA image
Enter the code shown above:

Matt Jura

Matt is a Front End Developer, UI designer, DotNetNuke, E-commerce and SEO specialist, responsible for large number of websites, including e-commerce and online catalogues for domestic and international clients.
View my portfolio on Behance
View my profile on KLOUT
Add me to your circles
Follow me on Twitter


Matt Jura on Twitter
New project going strong http://t.co/xBA4Zx04 #DotNetNuke Posted 27 days ago
@eagleworx tanks, these are txt/HTML tokens, I was looking for skin object - see 40fingers skin on codeplex. Resolved with txt/html :) Posted 53 days ago
@MattsDailyTweet #DotNetNuke User Avatar <img src="[PROFILE:PHOTO]" /> pasted in the editor as raw text + token replacement on Posted 53 days ago
Little help required #DotNetNuke - what is a skin token for the UserPhoto (avatar) - dnn 6.1+ Posted 53 days ago
Finally in new office, nearly a week later than planned but worth it, do not try to call me on old number :-) Posted 58 days ago
@darthberne @presleysylwia no to ustalmy date I powod sie znajdzie, moze w przyszlym tygodniu Posted 67 days ago
@presleysylwia @darthberne to moze wymyslimy powod na spotkanie I zrealizujemy pomysl na wspolne piwko ? Posted 67 days ago
@darthberne @presleysylwia powoli do przodu, nie mam co narzekac, caly czas w tym samym miejscu i z usmiechem na buzce :) Posted 67 days ago

Follow me

WSI DNN services