Help with a Simple Question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Terry

    Help with a Simple Question

    Hi,

    This is a newbie's question. I want to preload 4 images and only when
    all 4 images has been loaded into browser's cache, I want to start a
    slideshow() function. If images are not completed loaded into cache,
    the slideshow doesn't look very nice.

    I am not sure how/when to call the slideshow() function to make sure it
    starts after the preload has been completed.

    Thanks in advance for your help!

    Terry



    *************** *************** *************** *************** *
    <head>
    <script language="JavaS cript" type="text/JavaScript">
    <!--
    function MM_preloadImage s() {
    var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.leng th,a=MM_preload Images.argument s; for(i=0; i
    <a.length; i++)
    if (a[i].indexOf("#")!= 0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a
    [i];}}
    }

    function slideshow() {

    .....

    }

    //-->
    </script>
    </head>

    <body onload="MM_prel oadImages('01.j pg','02.jpg','0 3.jpg','04.jpg' )">


    </body>
    </html>
  • HikksNotAtHome

    #2
    Re: Help with a Simple Question

    In article <MPG.1a6a65a63c 49d3fc989680@ne ws.tc.umn.edu>, Terry
    <gobeyondgobeyo nd@REMOVE.yahoo .com> writes:
    [color=blue]
    >This is a newbie's question. I want to preload 4 images and only when
    >all 4 images has been loaded into browser's cache, I want to start a
    >slideshow() function. If images are not completed loaded into cache,
    >the slideshow doesn't look very nice.
    >
    >I am not sure how/when to call the slideshow() function to make sure it
    >starts after the preload has been completed.[/color]

    load it via the window.onload or in the body tag:

    window.onload = slideshow;

    in the script section, or:

    <body onload="slidesh ow()">

    The page will not be considered "loaded" until the images are loaded as well.
    --
    Randy

    Comment

    • Terry

      #3
      Re: Help with a Simple Question

      [color=blue]
      >
      > load it via the window.onload or in the body tag:
      >
      > window.onload = slideshow;
      >
      > in the script section, or:
      >
      > <body onload="slidesh ow()">
      >
      > The page will not be considered "loaded" until the images are loaded as well.[/color]

      Randy,

      I did the above. However, the slideshow starts before all the images
      are loaded.

      Terry

      Comment

      • Randy Webb

        #4
        Re: Help with a Simple Question

        Terry wrote:
        [color=blue][color=green]
        >>load it via the window.onload or in the body tag:
        >>
        >>window.onlo ad = slideshow;
        >>
        >>in the script section, or:
        >>
        >><body onload="slidesh ow()">
        >>
        >>The page will not be considered "loaded" until the images are loaded as well.[/color]
        >
        >
        > Randy,
        >
        > I did the above. However, the slideshow starts before all the images
        > are loaded.
        >
        > Terry[/color]

        <img src="image1.jpg " width="1" height="1">
        <img src="image2.jpg " width="1" height="1">
        <img src="image3.jpg " width="1" height="1">
        <img src="image4.jpg " width="1" height="1">

        and so on for each image. Then use the body's onload or window.onload to
        start the slideshow.

        Or, something is wrong with your preloading script. Post a URL to a
        sample page if you can't get it working.

        Comment

        • Terry

          #5
          Re: Help with a Simple Question

          [color=blue]
          > <img src="image1.jpg " width="1" height="1">
          > <img src="image2.jpg " width="1" height="1">
          > <img src="image3.jpg " width="1" height="1">
          > <img src="image4.jpg " width="1" height="1">
          >
          > and so on for each image. Then use the body's onload or window.onload to
          > start the slideshow.
          >
          > Or, something is wrong with your preloading script. Post a URL to a
          > sample page if you can't get it working.[/color]

          Hi Randy, Thanks for your help!



          Please take a look of the link if you have a minute. It has no problem
          with fast internet connection. However, over 56k modem, I can see that
          the slide show has started while down at the status bar, it says that X
          number of images remained to be downloaded.

          Terry

          Comment

          • Terry

            #6
            Re: Help with a Simple Question -- One More Link

            Randy,



            Can you take a look of this link as well? The slide show starts before
            the image loading bar gets 100%.

            I was wonder if there is way to call a function after the preloading
            complete. I am not sure where to stick in the nextAd() -- the slideshow
            function inside the image loading function.

            Thanks again!

            Terry

            Comment

            • Randy Webb

              #7
              Re: Help with a Simple Question

              Terry wrote:[color=blue][color=green]
              >><img src="image1.jpg " width="1" height="1">
              >><img src="image2.jpg " width="1" height="1">
              >><img src="image3.jpg " width="1" height="1">
              >><img src="image4.jpg " width="1" height="1">
              >>
              >>and so on for each image. Then use the body's onload or window.onload to
              >>start the slideshow.
              >>
              >>Or, something is wrong with your preloading script. Post a URL to a
              >>sample page if you can't get it working.[/color]
              >
              >
              > Hi Randy, Thanks for your help!
              >
              > http://free.hostdepartment.com/j/javashop/
              >
              > Please take a look of the link if you have a minute. It has no problem
              > with fast internet connection. However, over 56k modem, I can see that
              > the slide show has started while down at the status bar, it says that X
              > number of images remained to be downloaded.
              >[/color]

              Thats because your preload routing happens after the page has loaded.

              <body onload="MM_prel oadImages(snipp ed for brevity), nextAd()">

              Page loads.
              Preload routine starts, images start downloading.
              nextAd() starts.

              If you are wanting to ensure that the images load before the routine
              starts, then remove the preload from the onload, and load them during
              page processing.

              --
              Randy

              Comment

              • Terry

                #8
                Re: Help with a Simple Question

                [color=blue]
                > Thats because your preload routing happens after the page has loaded.
                >
                > <body onload="MM_prel oadImages(snipp ed for brevity), nextAd()">
                >
                > Page loads.
                > Preload routine starts, images start downloading.
                > nextAd() starts.
                >
                > If you are wanting to ensure that the images load before the routine
                > starts, then remove the preload from the onload, and load them during
                > page processing.[/color]

                Thanks again Randy! It makes sense. Just to make sure I understand.
                So if I put the following "preload" script in the <head> or <body> of a
                page, the 2 images get loaded before any "onload" routines start?

                During "page processing", do all the scripts embedded in <head> and
                <body> get executed before "onload" routines?

                <head>
                <script type="text/javascript" language="JavaS cript">

                var bannerAD=new Array("images/01.jpg","images/02.jpg");

                var preloadedimages =new Array();
                for (i=0;i<bannerAD .length;i++){
                preloadedimages[i]=new Image();
                preloadedimages[i].src=bannerAD[i];
                }
                </script>
                </head>

                Comment

                • Randy Webb

                  #9
                  Re: Help with a Simple Question

                  Terry wrote:[color=blue][color=green]
                  >>Thats because your preload routing happens after the page has loaded.
                  >>
                  >><body onload="MM_prel oadImages(snipp ed for brevity), nextAd()">
                  >>
                  >>Page loads.
                  >>Preload routine starts, images start downloading.
                  >>nextAd() starts.
                  >>
                  >>If you are wanting to ensure that the images load before the routine
                  >>starts, then remove the preload from the onload, and load them during
                  >>page processing.[/color]
                  >
                  >
                  > Thanks again Randy! It makes sense. Just to make sure I understand.
                  > So if I put the following "preload" script in the <head> or <body> of a
                  > page, the 2 images get loaded before any "onload" routines start?[/color]

                  Yes.
                  [color=blue]
                  > During "page processing", do all the scripts embedded in <head> and
                  > <body> get executed before "onload" routines?[/color]

                  Depends on what they do. But for the most part, yes.
                  [color=blue]
                  > <head>
                  > <script type="text/javascript" language="JavaS cript">
                  >
                  > var bannerAD=new Array("images/01.jpg","images/02.jpg");
                  >
                  > var preloadedimages =new Array();
                  > for (i=0;i<bannerAD .length;i++){
                  > preloadedimages[i]=new Image();
                  > preloadedimages[i].src=bannerAD[i];
                  > }
                  > </script>
                  > </head>[/color]

                  In theory it does. In practice, I haven't seen a situation where that
                  doesn't work. Doesn't mean there isn't one though.

                  P.S. The language attribute is not needed, type="text/javascript" is
                  sufficient on its own.

                  --
                  Randy

                  Comment

                  • Terry

                    #10
                    Re: Help with a Simple Question

                    Randy,

                    Thanks so much for your help! Here is a slightly off-subject question.
                    When I load the page, it seemed to me that images were loaded sequentially
                    based on their names. In other words, 01.jpg is loaded earlier than
                    logo.jpg. Am I imagining this or is it the order in which the images are
                    loaded onto a page?

                    Terry

                    Comment

                    • Randy Webb

                      #11
                      Re: Help with a Simple Question

                      Terry wrote:[color=blue]
                      > Randy,
                      >
                      > Thanks so much for your help! Here is a slightly off-subject question.
                      > When I load the page, it seemed to me that images were loaded sequentially
                      > based on their names. In other words, 01.jpg is loaded earlier than
                      > logo.jpg. Am I imagining this or is it the order in which the images are
                      > loaded onto a page?
                      >
                      > Terry[/color]

                      You are imagining it. They are loaded in the order they appear. Whether
                      its in ABC order or not.

                      Please read the FAQ with regards to quoting.

                      --
                      Randy

                      Comment

                      • Terry

                        #12
                        Re: Help with a Simple Question

                        [color=blue]
                        > Please read the FAQ with regards to quoting.[/color]

                        Randy,

                        I checked this link: http://jibbering.com/faq/
                        but didn't find anything there.

                        I would also like to understand how a browser decides what to do with
                        text, table, img, script ... on a page. Are there any resources on the
                        web that provide some info in this regard?

                        Thanks again for your generous help!

                        Terry

                        Comment

                        • Michael Winter

                          #13
                          Re: Help with a Simple Question

                          On Tue, 13 Jan 2004 15:36:19 -0600, Terry
                          <gobeyondgobeyo nd@REMOVE.yahoo .com> wrote:
                          [color=blue]
                          >[color=green]
                          >> Please read the FAQ with regards to quoting.[/color]
                          >
                          > Randy,
                          >
                          > I checked this link: http://jibbering.com/faq/
                          > but didn't find anything there.[/color]

                          I believe the relevant link was to http://www.ietf.org/rfc/rfc1855.txt (in
                          FAQ section 2.3). This document gives etiquette guidelines that should be
                          observed during communication on the Internet. The most appropriate advice
                          was:

                          "If you are sending a reply to a message or a posting be sure you
                          summarize the original at the top of the message, or include
                          just enough text of the original to give a context. This will
                          make sure readers understand when they start to read your
                          response. Since NetNews, especially, is proliferated by
                          distributing the postings from one host to another, it is
                          possible to see a response to a message before seeing the
                          original. Giving context helps everyone. But do not include
                          the entire original!"

                          Except from RFC 1855, Section 3.1.1, General Guidelines for
                          mailing lists and NetNews
                          [color=blue]
                          > I would also like to understand how a browser decides what to do with
                          > text, table, img, script ... on a page. Are there any resources on the
                          > web that provide some info in this regard?[/color]

                          Are you referring to the parsing of HTML, or its display once it's been
                          parsed?

                          Mike

                          --
                          Michael Winter
                          M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

                          Comment

                          • Terry

                            #14
                            Re: Help with a Simple Question

                            [color=blue]
                            >
                            > Are you referring to the parsing of HTML, or its display once it's been
                            > parsed?
                            >
                            > Mike
                            >[/color]

                            Mainly parsing. Thanks Mike!

                            Terry

                            Comment

                            • Randy Webb

                              #15
                              Re: Help with a Simple Question

                              Terry wrote:[color=blue][color=green]
                              >>Please read the FAQ with regards to quoting.[/color]
                              >
                              >
                              > Randy,
                              >
                              > I checked this link: http://jibbering.com/faq/
                              > but didn't find anything there.[/color]


                              specifically, but the entire document.

                              2.3 deals with what/how to quote and what not to quote.
                              [color=blue]
                              > I would also like to understand how a browser decides what to do with
                              > text, table, img, script ... on a page. Are there any resources on the
                              > web that provide some info in this regard?[/color]

                              What resource you use would depend on what you are trying to find out.
                              And what browser you are researching.


                              --
                              Randy

                              Comment

                              Working...