views:

1098

answers:

2

Hello all,

I'm struggling with this, maybe some of you can help...

  • I have a home page slideshow with large images at www.theoribeiro.com using jQuery Cycle plugin

  • Images are large and sometimes with slow connections (but even in fast ones) the behavior of the slideshow start is pretty ugly, showing the image all of a sudden or half-loaded.

  • I want to make sure that at least the 2 or 3 first images are loaded before the slideshow starts and meanwhile I want to run a loading animated gif, then I want to fade in the first image.

I searched a lot on the internet and on the forums and tried loads of stuff with my limited knowledge of javascript and jQuery but could't come up with a solution.

Any help would be greatly appreciated!!!

A: 

Don't initialize the Cycle plugin until you have your images loaded. Use a preloading script like this one - http://jquery-howto.blogspot.com/2009/02/preload-images-with-jquery.html and after you have 2-3 images which you keep hidden you can initialize the Cycle plugin. Because your images are already in the cache you should not have problems with half shown images. By default display the loading image and hide it once you initialize the Cycle plugin.

// In response to the first comment

You can use plugin like this - http://plugins.jquery.com/project/ImageLoader and use PHP to generate the javascript. For example:

$("#slideShow").imageLoader({
   images: [
    <?php
        // You can populate this array from readin a directory or manually it is your choice.
        $images = array('1.jpg', '2.jpg');
        $l = count($images);
        for(int $i=1; $i<$l; $i++) {
            echo ($i>0 ? ',' : '') . "{src: '" . $v . "'}";
        }
    ?>
    ]}, function () {
        $('#slideShow').cycle();
    });
Ivo Sabev
Hi Ivo, thanks a lot for the fast response! I looked at the link you sent but I don't quite know how it could work for me because:-my html pages are created dynamically through PHP so I don't know the exact images I need to preload to specifically call them in the jQuery preload.-I can modify the PHP output so the images are links in anchor tags, list items, divs or whatever but I can't know in advanced what images they are.-I have very limited knowledge in jQuery or Javascript although I built my whole page. If someone would be willing to teach something I will definitely learn!Thx!!
Theo Ribeiro
I modified my answer to address your concerns.
Ivo Sabev
Hi Ivo, thank you a lot for the feedback. I'll look into it though I'll also keep looking for a 100% jQuery solution without messing with the PHP files as I would rather only change the image container's output in the PHP... It's because I'm using a wordpress plugin (NextGen Gallery) to generate the image list and messing with the plugin PHP makes it all more difficult for upgrades, etc... in the future. A pure jQuery solution would be nice and clean! :)Thanks a lot!
Theo Ribeiro
A: 

I have the same issue as Theo Ribeiro. I have a WordPress NextGen Carousel - which uses Jquery Cycle and JQuery - that loads images. One large image, plus thumbnails leading to the next images. None of the large images are preloaded. As I will have many galleries - about 20 of 10 images each - a basic javascript preloader listing all the images that need preloading is not really efficient and would make the preloading take too long. The same goes for a javascript or JQuery option to load all images form a folder. Two hundred images is just too much. Any efficient JQuery or JQuery Cycle solution for this?