Does this make sense?

Discussion in 'Javascript' started by Adrian MacNair, Jun 7, 2005.

  1. Because it's not working...

    I want a condition where if only the images are all preloaded then the slide
    show will work:

    <script type="text/javascript">
    var imagesdone=false;
    window.onload=loadimages;
    function loadimages() {
    var images=new Array();
    for (var i=0;i<myImages.length;i++) {
    images=new Image();
    images.src=myImages;
    }
    imagesdone=true;
    }
    // This is an onClick event
    function startslideshow() {
    if (imagesdone) {
    do slideshow stuff
    } else {
    alert('Sorry, images are not loaded for viewing yet')
    }
    }
    </script>
     
    Adrian MacNair, Jun 7, 2005
    #1
    1. Advertising

  2. Adrian  MacNair

    Randy Webb Guest

    Adrian MacNair wrote:
    > Because it's not working...
    >
    > I want a condition where if only the images are all preloaded then the slide
    > show will work:
    >
    > <script type="text/javascript">
    > var imagesdone=false;
    > window.onload=loadimages;
    > function loadimages() {
    > var images=new Array();
    > for (var i=0;i<myImages.length;i++) {
    > images=new Image();
    > images.src=myImages;
    > }
    > imagesdone=true;


    That doesn't ensure the images are loaded, it only ensures that the
    request was made for the image. The imagesdone is set to true before the
    first image is even downloaded.


    Have the images preloaded while the page loads, then the window.onload
    won't fire until they are loaded. Another possibility is to add an
    onload to each preloaded image that will call a function that
    incremements a counter, then checks the counter. If the counter matches
    myImages.length then they are all loaded and it will set imagesdone to true.

    > }
    > // This is an onClick event
    > function startslideshow() {
    > if (imagesdone) {
    > do slideshow stuff
    > } else {
    > alert('Sorry, images are not loaded for viewing yet')
    > }
    > }
    > </script>
    >
    >



    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
     
    Randy Webb, Jun 7, 2005
    #2
    1. Advertising

  3. Adrian  MacNair

    alu Guest

    Another possibility is to write the images into the page but not display
    them; the <body> onload would fire only when all images are loaded.
    -alu


    <script type="text/javascript">

    var imagesdone=false;

    // This is an onClick event
    function startslideshow() {
    if (imagesdone) {
    alert("do slide show") ;
    } else {
    alert('Sorry, images are not loaded for viewing yet')
    }
    }
    </script>


    </head>
    <body onload="imagesdone=true;">

    <a href="#" onclick="startslideshow()">test images loaded?</a>

    <script>
    for (var im=0;im<myImages.length;im++) {
    document.write('<img src="'+myImages[im]+'" alt=""
    style="display:none">')
    }

    </script>

    </body>
     
    alu, Jun 7, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Phil Sandler

    NULLs from SQL--does this make sense?

    Phil Sandler, Aug 19, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    334
    Phil Sandler
    Aug 19, 2004
  2. Jason
    Replies:
    0
    Views:
    350
    Jason
    Oct 12, 2004
  3. Timo Nentwig
    Replies:
    31
    Views:
    1,207
    Chris Smith
    May 13, 2004
  4. milkyway

    Does this make sense?

    milkyway, Dec 2, 2004, in forum: Java
    Replies:
    0
    Views:
    377
    milkyway
    Dec 2, 2004
  5. milkyway

    Does this make sense?

    milkyway, Dec 2, 2004, in forum: Java
    Replies:
    2
    Views:
    339
Loading...

Share This Page