Wondering if this can be improved?

Discussion in 'JavaScript' started by Jen-, Nov 11, 2006.

  1. #1
    Hello, when a page first loads these images do really strange things. The timing is set to a second just to make it easier to show the problem.

    When the page first loads the image can time for more quickly or more slowly for several minutes.

    I realize when items first load that can affect these type of things.
    But hoping someone can see a better way to rotate it to minimize this problem, so it happens less often. Please let me know, thank you very much, Jen. <BODY onload="change();"><img id="img" border="0">

    arr = new Array(
    ["http://www.website.com/test1.jpg"],
    ["http://www.website.com/test2.jpg"]
    );


    var counter = 0;
    function change()
    { document.getElementById("img").src = arr[counter][0]
    counter++; if (counter == arr.length)
    {counter = 0; } setTimeout('change()', 1000)}
     
    Jen-, Nov 11, 2006 IP
  2. Jen-

    Jen- Peon

    Messages:
    151
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Someone said I should add an interval to the above to keep it executing no sooner than a second. That way no matter what the browser causes they still will not launch too early. Seems I have more of a problem with some executing too quickly instead of a delay. Anyone know how to do this? Thank you.
     
    Jen-, Nov 12, 2006 IP