0

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!!!

Theo Ribeiro
  • 1
  • 1
  • 1
  • possible duplicate of [Preload images for jQuery Cycle Plugin](http://stackoverflow.com/questions/427192/preload-images-for-jquery-cycle-plugin) – sje397 Oct 05 '10 at 04:08

1 Answers1

1

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
  • 5,230
  • 1
  • 26
  • 38
  • 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 Apr 06 '10 at 20:21
  • I modified my answer to address your concerns. – Ivo Sabev Apr 06 '10 at 20:55
  • 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 Apr 06 '10 at 21:18