Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Mar 2005
    Posts
    115
    Thanks
    3
    Thanked 0 Times in 0 Posts

    completed loading function not working?

    Hi,

    I am using the following code in a page within a frameset. The frame id is "imagepage".

    I want to scroll to a fixed position on loading, and because there are a number of large images loading, i figured I'd need to check the load status before attempting the scroll command.

    I'm using the code as follows, but the scroll is not happening.

    I also tried the last line using "parent.imageframe.window.scrollTo" but still no effect. I put an alert between the setInterval and the scrollTo statements, and the alert comes up even though I can still see the page loading indicator running.

    Any help gratefully appreciated.

    --------------------
    in the <HEAD>:

    function checkloaded()
    {
    alldone = document.images.length;
    temp = new Array(0);
    for (var i=0;i<alldone;i++)
    {
    if (document.images[i].complete)
    {
    temp[temp.length] = i
    }
    }

    if (temp.length == alldone) {clearInterval(waitcheckloaded);}
    }

    and in the <BODY>:

    a number of images are loaded in DIV statements for example
    <div class="divstylev" id="layer01"><img src="i01.jpg" height="32767" width="32767"></div>

    and after that I have the statements

    waitcheckloaded = setInterval("checkloaded()", 10);
    window.scrollTo(15000, 15000);
    ------------------------

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    I think that the problem could be

    setInterval("checkloaded()", 10);

    as 10 milliseconds is not long enough for the image to load.

    Try (say) 5000 (= 5 seconds)

  • #3
    Regular Coder
    Join Date
    Mar 2005
    Posts
    115
    Thanks
    3
    Thanked 0 Times in 0 Posts
    As far as I understand, the interval length will simply affect the number of iterations of the loop. The function should still loop until all images are loaded and then the interval be cleared.

    The problem here is that the "loaded" alert is appearing INSTANTLY, before the checkloaded function has even iterated once!

    I have modified the function slightly, added more alerts as follows:
    -----------------------
    function checkloaded()
    {
    alldone = document.images.length;
    alert("alldone is " + alldone);
    var temp = 0;
    for (var i=0;i<alldone;i++)
    {
    alert("i is " + i); j = 100+i; alert("j is " + j);
    if (document.getElementById('img' + j).complete)
    {
    temp+=1
    };
    };
    alert("temp is " + temp);
    if (temp == alldone) {clearInterval(waitcheckloaded);}
    }

    I have modified the DIV statements as follows:
    <div class="divstylev" id="layer01"><img src="i01.jpg" height="32767" width="32767" id="img101"></div>

    and in the body put:
    waitcheckloaded = setInterval("checkloaded()", 1000);
    alert('loaded');
    parent.imageframe.window.scrollto(15000, 15000);
    -----------------------------------------

    And now things are completely confusing me.

    The loop starts after a few seconds (the interval time?), and I see:

    alldone is 10 (i.e. the number of images)
    i is 0
    j is 100
    alldone is 10
    i is 0
    j is 100
    alldone is 10
    and so on again and again and again. But I NEVER see the alert "temp is..." - wtf?? It's the next statement in the function!
    I must be missing something really obvious, but cannot see where.

    Eventually the images appear on screen as they have completed loading, but I am still locked inside this looping function, which obviously has not done its job.

    Any help appreciated please....


  •  

    Posting Permissions

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