SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict caser85's Avatar
    Join Date
    May 2002
    Posts
    262
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to preload images in separate file?

    I moved all the javascript needed to saw images on my page. There is one thing left though, and that is that the images are being preloaded in the <body> tag. Is there a way to preload the images in the attached script instead of doing in it in the body tag? Here is the link to my work in progess:

    http://www.midwestmarket.net/rotc/new/large_menu.html

    Thanks!
    Casey

  2. #2
    + platinum's Avatar
    Join Date
    Jun 2001
    Location
    Adelaide, Australia
    Posts
    6,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should be able to put the preload code into your .js file along with your rollover script and call it as a function using onload...

    Unless you were trying to get rid of unload from the body tage that is...

  3. #3
    SitePoint Addict caser85's Avatar
    Join Date
    May 2002
    Posts
    262
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, I have the onload script in my .js file. I actually wanted to move the onload portion of the body tag into the javascript file. Maybe I'm asking for too much though. I just want to simplify things. Do you know how I could do this or is it not possible?

  4. #4
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the script I use for my rollovers/preload. It could easily be put into an external file.

    <script language="javascript">
    <!--

    if (document.images) {

    nav_bio_on = new Image();
    nav_bio_on.src = "images/nav_bio_on.gif";
    nav_bio_off = new Image();
    nav_bio_off.src = "images/nav_bio_off.gif";

    }

    function changeImages() {
    if (document.images) {
    for (var i=0; i<changeImages.arguments.length; i+=2) {
    document[changeImages.arguments[i]].src = eval(changeImages.arguments[i+1] + ".src");
    }
    }
    }

    // -->
    </script>

    Simply duplicate the 4 lines above for each image you want to preload.
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  5. #5
    SitePoint Addict caser85's Avatar
    Join Date
    May 2002
    Posts
    262
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by creole
    This is the script I use for my rollovers/preload. It could easily be put into an external file.

    <script language="javascript">
    <!--

    if (document.images) {

    nav_bio_on = new Image();
    nav_bio_on.src = "images/nav_bio_on.gif";
    nav_bio_off = new Image();
    nav_bio_off.src = "images/nav_bio_off.gif";

    }

    // -->
    </script>

    Simply duplicate the 4 lines above for each image you want to preload.
    So you're saying that by adding those lines into my external script, that it will preload the images without having to call the function in every page? That would be great if it did. Please advise.

  6. #6
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes...that's how it works. Putting a preload call to every image in the BODY tag is not only messy but it's not portable. You have to change every page.
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  7. #7
    My precious!!! astericks's Avatar
    Join Date
    Mar 2002
    Location
    Vancouver, BC
    Posts
    1,971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just part of my experience...i once put the preloading in a js file and used the <body onload> to call the function. the rollovers were slow though...maybe i messed up.

    Anyway, i dont use it anymore.


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
  •