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 5 of 5
  1. #1
    New Coder
    Join Date
    May 2012
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    function won't stop being called

    Code:
    function inPrevPage() {
        inPrevPageCount();
        resetIterPrevPage();
    }
    function inPrevPageCount() {
        if ((iterInPrevPage>=0)&&(iterInPrevPage<40)) {
            iterInPrevPage++;
            inPrevPageMove();
        }
    }
    function resetIterPrevPage() {
        iterInPrevPage=0;
    }
    function inPrevPageMove() {
        var jPrevPage=document.getElementById("prevpage");
        var jPrevPage_left=jPrevPage.style.left==""?-117:parseFloat(jPrevPage.style.left);
        if (jPrevPage_left<26) {
            jPrevPage_left=jPrevPage_left+speedPxPrevPage;
            jPrevPage.style.left=jPrevPage_left+"px";
            setTimeout(inPrevPage,16);
        }
        else if ((jPrevPage_left>=26)&&(jPrevPage_left<96)) {
            speedPxPrevPage=speedPxPrevPage/1.25;
            jPrevPage_left=jPrevPage_left+speedPxPrevPage;
            jPrevPage.style.left=jPrevPage_left+"px";
            setTimeout(inPrevPage,16);
        }
    }
    Simply put, I'm trying to make inPrevPage() execute 40 times. The variable iterPrevPage needs to reset to 0 once inPrevPage has executed 40 times, so that it can do so again in the future.

    If I add an alert here:

    Code:
        else if ((jPrevPage_left>=26)&&(jPrevPage_left<96)) {
            speedPxPrevPage=speedPxPrevPage/1.25;
            jPrevPage_left=jPrevPage_left+speedPxPrevPage;
            jPrevPage.style.left=jPrevPage_left+"px";
            setTimeout(inPrevPage,16);
            alert("inPrevPage() called");
        }
    }
    ...the alert keeps on displaying indefinitely. Can someone tell me what's wrong with my code?
    Last edited by transmoderata; 06-18-2012 at 08:30 PM.

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Every time you call inPrevPage() you reset the counter to 0 so it will never reach 40.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #3
    New Coder
    Join Date
    May 2012
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I was of the idea that inPrevPageCount() would finish executing, THEN resetIterPrevPage() would be called. And debugging with Firebug, I see that iterInPrevPage is reaching 40. So I don't think this is the problem.

  • #4
    New Coder
    Join Date
    May 2012
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I've written the code in a slightly different way to see what it does:

    Code:
    function inPrevPage() {
        inPrevPageMove();
        resetIterInPrevPage();
    }
    function resetIterInPrevPage() {
        iterInPrevPage=0;
    }
    function inPrevPageMove() {
        var jPrevPage=document.getElementById("prevpage");
        var jPrevPage_left=jPrevPage.style.left==""?-117:parseFloat(jPrevPage.style.left);
        if ((jPrevPage_left<26)&&(iterInPrevPage>=0)&&(iterInPrevPage<40)) {
            jPrevPage_left=jPrevPage_left+speedPxPrevPage;
            jPrevPage.style.left=jPrevPage_left+"px";
            iterInPrevPage++;
            setTimeout(inPrevPageMove,16);
        }
        else if ((jPrevPage_left>=26)&&(jPrevPage_left<96)&&(iterInPrevPage>=0)&&(iterInPrevPage<40)) {
            speedPxPrevPage=speedPxPrevPage/1.25;
            jPrevPage_left=jPrevPage_left+speedPxPrevPage;
            jPrevPage.style.left=jPrevPage_left+"px";
            iterInPrevPage++;
            setTimeout(inPrevPageMove,16);
        }
    }
    (note that the function previously named resetIterPrevPage() is now named resetIterInPrevPage() )

    Now in Firebug I can see that when inPrevPage() is called, iterInPrevPage reaches 40 but doesn't reset.

    ???

  • #5
    New Coder
    Join Date
    May 2012
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If found the problem. I wasn't resetting speedPxPrevPage and speedPxNextPage to 15 after each run-though. The functions were calling, the images were just moving extremely slow.


  •  

    Posting Permissions

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