Results 1 to 3 of 3

Thread: Preloading images for Accordion Menu script

  1. #1
    Join Date
    Aug 2005
    Posts
    54
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Preloading images for Accordion Menu script

    1) Script Title: Accordion Menu

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...enu-glossy.htm

    3) Describe problem: I'd like to add a script that preloads all the images. Can someone assist?

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Well, loading and preloading take the same amount of time, so if there are any images that will be displayed anyway, as the page loads, don't bother with them. Also, preloading is best used only for small images, like for a menu, so if I understand you correctly, it would be fine here. A nice and simple preload routine is:

    Code:
    <script type="text/javascript">
    if(document.images)
    (function(){
    var myImages = ['some.gif', 'another.gif', 'image73.gif', 'bobs.gif'];
    for (var s, i = myImages.length - 1; i > -1; --i){
    s = myImages[i];
    myImages[i] = new Image();
    myImages[i].src = s;
    }
    })();
    </script>
    List as many images as you like, but try to keep it down to just essential, small images that won't otherwise be loaded with the page. The above may be placed in the head of your page, or its code:

    Code:
    if(document.images)
    (function(){
    var myImages = ['some.gif', 'another.gif', 'image73.gif', 'bobs.gif'];
    for (var s, i = myImages.length - 1; i > -1; --i){
    s = myImages[i];
    myImages[i] = new Image();
    myImages[i].src = s;
    }
    })();
    may be placed at the beginning of the ddaccordion.js file. If placing it in an external file, it's best to use the absolute paths to the images.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    AshleyQuick (12-07-2008)

  4. #3
    Join Date
    Aug 2005
    Posts
    54
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    Very nice, thank you!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •