Multiple setTimeout in function?

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

    Multiple setTimeout in function?

    Hi,

    I'm not exactly sure why this doesn't work. I'm basically just trying a
    simple approach at a slide down div.

    function slide_div {


    setTimeout("doc ument.getElemen tById('mydiv'). style.length='1 0px';",1000);

    setTimeout("doc ument.getElemen tById('mydiv'). style.length='2 0px';",1000);

    setTimeout("doc ument.getElemen tById('mydiv'). style.length='3 0px';",1000);

    setTimeout("doc ument.getElemen tById('mydiv'). style.length='4 0px';",1000);

    setTimeout("doc ument.getElemen tById('mydiv'). style.length='5 0px';",1000);

    setTimeout("doc ument.getElemen tById('mydiv'). style.length='6 0px';",1000);

    }

    It seems like it just runs the last setTimeout line and pops out all at
    once. I've even tried adding a=, b=, c=,. etc at the begining of each
    line to no avail.

    Anybody know a simple solution for this?

    Thanks,
    Max

  • knizacky@gmail.com

    #2
    Re: Multiple setTimeout in function?


    Max wrote:
    Hi,
    >
    I'm not exactly sure why this doesn't work. I'm basically just trying a
    simple approach at a slide down div.
    >
    function slide_div {
    >
    >
    setTimeout("doc ument.getElemen tById('mydiv'). style.length='1 0px';",1000);
    >
    setTimeout("doc ument.getElemen tById('mydiv'). style.length='2 0px';",1000);
    >
    setTimeout("doc ument.getElemen tById('mydiv'). style.length='3 0px';",1000);
    >
    setTimeout("doc ument.getElemen tById('mydiv'). style.length='4 0px';",1000);
    >
    setTimeout("doc ument.getElemen tById('mydiv'). style.length='5 0px';",1000);
    >
    setTimeout("doc ument.getElemen tById('mydiv'). style.length='6 0px';",1000);
    >
    }
    >
    It seems like it just runs the last setTimeout line and pops out all at
    once. I've even tried adding a=, b=, c=,. etc at the begining of each
    line to no avail.
    >
    Anybody know a simple solution for this?
    >
    Thanks,
    Max
    Increment your milliseconds instead of using 1000 for all of them. e.g.
    1000,2000,etc

    Comment

    • Evertjan.

      #3
      Re: Multiple setTimeout in function?

      Max wrote on 10 okt 2006 in comp.lang.javas cript:
      I'm not exactly sure why this doesn't work. I'm basically just trying a
      simple approach at a slide down div.
      >
      function slide_div {
      a function needs ()
      setTimeout("doc ument.getElemen tById
      ('mydiv').style .length='10px'; ",1000);
      >
      setTimeout("doc ument.getElemen tById
      ('mydiv').style .length='20px'; ",1000);
      >
      setTimeout("doc ument.getElemen tById
      ('mydiv').style .length='30px'; ",1000);
      >
      setTimeout("doc ument.getElemen tById
      ('mydiv').style .length='40px'; ",1000);
      >
      setTimeout("doc ument.getElemen tById
      ('mydiv').style .length='50px'; ",1000);
      >
      setTimeout("doc ument.getElemen tById
      ('mydiv').style .length='60px'; ",1000);
      >
      >}
      >
      It seems like it just runs the last setTimeout line and pops out all at
      once. I've even tried adding a=, b=, c=,. etc at the begining of each
      line to no avail.

      They start all at [nearly] the same time,
      so they all fire at [nearly] the same second later.
      setTimeout() is NOT a wait() function.

      Try:

      =============== =============== ====
      var mydiv = document.getEle mentById('mydiv ');
      var myLength = 0;
      slide_div();

      function slide_div() {
      mydiv.style.len gth= myLength + 'px';
      myLength += 10;
      if (myLength<=60)
      setTimeout("sli de_div()",1000) ;
      };
      =============== =============== =====

      not tested.

      --
      Evertjan.
      The Netherlands.
      (Please change the x'es to dots in my emailaddress)

      Comment

      • Max

        #4
        Re: Multiple setTimeout in function?



        On Oct 10, 11:03 am, "Evertjan." <exjxw.hannivo. ..@interxnl.net wrote:
        Max wrote on 10 okt 2006 in comp.lang.javas cript:
        >
        I'm not exactly sure why this doesn't work. I'm basically just trying a
        simple approach at a slide down div.
        >
        function slide_div {a function needs ()
        >
        setTimeout("doc ument.getElemen tById('mydiv'). style.length='1 0px';",1000);
        >
        setTimeout("doc ument.getElemen tById('mydiv'). style.length='2 0px';",1000);
        >
        setTimeout("doc ument.getElemen tById('mydiv'). style.length='3 0px';",1000);
        >
        setTimeout("doc ument.getElemen tById('mydiv'). style.length='4 0px';",1000);
        >
        setTimeout("doc ument.getElemen tById('mydiv'). style.length='5 0px';",1000);
        >
        setTimeout("doc ument.getElemen tById('mydiv'). style.length='6 0px';",1000);
        >
        >
        >
        }
        >
        It seems like it just runs the last setTimeout line and pops out all at
        once. I've even tried adding a=, b=, c=,. etc at the begining of each
        line to no avail.They start all at [nearly] the same time,
        so they all fire at [nearly] the same second later.
        setTimeout() is NOT a wait() function.
        >
        Try:
        >
        =============== =============== ====
        var mydiv = document.getEle mentById('mydiv ');
        var myLength = 0;
        slide_div();
        >
        function slide_div() {
        mydiv.style.len gth= myLength + 'px';
        myLength += 10;
        if (myLength<=60)
        setTimeout("sli de_div()",1000) ;};============ =============== ========
        >
        not tested.
        Thanks for the suggestions. This worked fine and I now understand what
        I was doing wrong.

        Max

        Comment

        • Robin

          #5
          Re: Multiple setTimeout in function?

          Max wrote:
          document.getEle mentById('mydiv ').style.length ='10px'
          Err, what's 'length'? I don't see this property at:
          Sorry! We can't seem to find the resource you're looking for


          Shouldn't it be 'width' or 'height', or am I missing something?

          Robin

          Comment

          • Dr John Stockton

            #6
            Re: Multiple setTimeout in function?

            JRS: In article <1160495272.780 219.19250@k70g2 000cwa.googlegr oups.com>,
            dated Tue, 10 Oct 2006 08:47:52 remote, seen in
            news:comp.lang. javascript, Max <max@kipness.co mposted :
            >
            >Anybody know a simple solution for this?
            FAQ 4.20.

            It's a good idea to read the newsgroup and its FAQ. See below.
            --
            © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
            <URL:http://www.jibbering.c om/faq/>? JL/RC: FAQ of news:comp.lang. javascript
            <URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
            <URL:http://www.merlyn.demo n.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.

            Comment

            • Dr John Stockton

              #7
              Re: Multiple setTimeout in function?

              JRS: In article <egibhj$4bf$1@g emini.csx.cam.a c.uk>, dated Wed, 11 Oct
              2006 09:55:15 remote, seen in news:comp.lang. javascript, Robin
              <anon@somewhere .composted :
              >Max wrote:
              >document.getEl ementById('mydi v').style.lengt h='10px'
              >
              >Err, what's 'length'? I don't see this property at:
              >http://www.w3schools.com/css/css_reference.asp
              Not the most reliable of sites, IIRC, but it should be OK here.
              >Shouldn't it be 'width' or 'height', or am I missing something?
              I'd suggest 'fontSize'. But specifying absolute font-sizes is generally
              deprecated.

              --
              © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
              <URL:http://www.jibbering.c om/faq/>? JL/RC: FAQ of news:comp.lang. javascript
              <URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
              <URL:http://www.merlyn.demo n.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.

              Comment

              Working...