SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Bournemouth, South UK
    1 Post(s)
    0 Thread(s)

    setTimeout in a loop, followed by function

    i'm trying to set a for command from 1-200, using the number for movement until it gets to 150, then at 200 it goes on to another page.

    here's what I use, abit longwinded....
    function moveit() {
    if (pp<150) {[280-(pp/2)] }
    if (pp<200) {pp++}
    if (pp==200) {pp=201; cont()}
    setTimeout(moveit, [pp/20])}
    function cont() {top.location.href="nextpage.html" }

    what I need is a setTimeout for a 'for' loop rather than a function, and a trigger for when a for command is complete(or am I better of using the last number of the FOR command)

    I had to use the pp=201 to stop it from repeating at 200, offline it worked well, online it kept trying to load the next page, as it was staying on 200 but not going to the next page fast enough!!!! Kept on trying to load the next page from the first page
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Dallas, TX
    0 Post(s)
    0 Thread(s)
    You need to assign the timeout to a variable, so that it can later be referenced for clearing...

    if (pp==200) {clearTimeout(timer); cont()}
    var timer = setTimeout(moveit, [pp/20])}

    That what you need?
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev


Posting Permissions

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