SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member Janne's Avatar
    Join Date
    Jan 2003
    Location
    Cambridge
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help me, Im a spaz and my gradual resize script

    Any ideas on why this script isnt working, I think I've turned into an idiot.

    Feel free to tear it apart.


    <html>
    <head>
    <title>
    Test Interface
    </title>
    <script languange="Javascript" type="text/javascript">

    var gotolevel = 200;
    var prevlevel = 50;

    function resize(target)
    {

    target = document.getElementById(target);
    target.style.height = prevlevel;
    prevlevel = target.style.height;


    if(prevlevel < gotolevel)
    {
    target.style.height = prevlevel+10;

    if(prevlevel < gotolevel)
    {
    setTimeout("resize()", 1);
    }
    }
    else if(prevlevel > gotolevel)
    {

    target.style.height = prevlevel-10;
    if(prevlevel > gotolevel)
    {
    setTimeout("resize()", 1);
    }
    }
    else
    {
    //null condition
    }

    }
    </script>
    </head>

    <body onload="resize('box1')">

    <div id="box1" style="border: solid black 1px;">
    The "Dynamic" Div
    </div>

    <div>
    <hr />
    The other Div
    <hr />
    </div>

    </body>
    </html>

    It should set the height of the division to the 'prevlevel' (which it does) then gradually increment it until it's the size of 'gotolevel' (which it dont).

    I'm lost

  2. #2
    SitePoint Evangelist compwizard's Avatar
    Join Date
    May 2002
    Location
    United States
    Posts
    457
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    don't know why, but resize only runs once...then it goes to the null part of the loop....let me look more closely.
    Compwizard
    "There are 10 kinds of people in this world -- those who know binary, and those who don't."

  3. #3
    SitePoint Evangelist compwizard's Avatar
    Join Date
    May 2002
    Location
    United States
    Posts
    457
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is a version of the code that works:

    PHP Code:
    <html>
    <
    head>
    <
    title>
    Test Interface
    </
    title>
    <
    script languange="Javascript" type="text/javascript">

    var 
    gotolevel 200;
    var 
    prevlevel 50;

    function 
    resize(target)
    {
        
    target document.getElementById(target);
        
    target.style.height prevlevel;

        if(
    prevlevel gotolevel)
        {

            
    prevlevel prevlevel 10;
            
    target.style.height prevlevel
            
    if(prevlevel gotolevel)
            {
                
                
    setTimeout("resize('box1')"1);
            }
        }
        else if(
    prevlevel gotolevel)
        {
            
    prevlevel prevlevel 10;
            
    target.style.height prevlevel
            
    if(prevlevel gotolevel)
            {
                
    setTimeout("resize('box1')"1);
            }
        }
        else
        {
            
    //null condition
        
    }

    }
    </script>
    </head>

    <body onload="resize('box1')">

    <div id="box1" style="border: solid black 1px;">
    The "Dynamic" Div
    </div>

    <div>
    <hr />
    The other Div
    <hr />
    </div>

    </body>
    </html> 
    Compwizard
    "There are 10 kinds of people in this world -- those who know binary, and those who don't."

  4. #4
    SitePoint Member Janne's Avatar
    Join Date
    Jan 2003
    Location
    Cambridge
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow that is amazing! Even better than I imagined it Simple things for simple minds eh.

    But thanks a lot that has made my day (in a really sad way)
    When you can't see the angles no more..no more no more no more.. You're in Trouble..
    ..trouble ..trouble ..trouble


  5. #5
    SitePoint Evangelist compwizard's Avatar
    Join Date
    May 2002
    Location
    United States
    Posts
    457
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow that is amazing! Even better than I imagined it
    What is so amazing?? Why is so great??


    Anyway...Just glad I could help.
    Compwizard
    "There are 10 kinds of people in this world -- those who know binary, and those who don't."

  6. #6
    SitePoint Member Janne's Avatar
    Join Date
    Jan 2003
    Location
    Cambridge
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well I've been pulling my hair out trying to make a script do that, javascript was something I've never really taken the time to properly learn. Posting a message on here was kind of my last resort.

    So seeing it finally work was great, plus it looked smoother than I thought it might.

    cheers again
    When you can't see the angles no more..no more no more no more.. You're in Trouble..
    ..trouble ..trouble ..trouble



Bookmarks

Posting Permissions

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