SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2001
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    setTimeout faster

    hi
    how do i make this function go faster?
    its a sliding menu but it comes accross the screen too slow, refreshing the function every second.

    heres a bit of the code ...if i change the setTimeout to 100 it just goes slower ... how do i get milliseconds?

    <script language="JavaScript" type="text/javascript">
    <!--


    inc = -100
    pos = 20
    function move(){
    if(document.getElementById('test').style.pixelLeft<=pos){
    document.getElementById('test').style.display='block'
    document.getElementById('test').style.pixelLeft=inc++;
    setTimeout("move()",1)
    }
    }
    //-->
    </script>

    cheers chris

  2. #2
    JavaScript Guru (Big Ego) Arielladog's Avatar
    Join Date
    Jul 1999
    Location
    SC, USA
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    JavaScript just can't repeat a function that fast. Anyway, try something like:

    Code:
    <script language="JavaScript" type="text/javascript"> 
    <!-- 
    
    
    inc = -100 
    pos = 20 
    function move(){ 
    if(document.getElementById('test').style.pixelLeft<=pos){ 
    document.getElementById('test').style.display='block'
    document.getElementById('test').style.pixelLeft=inc;
    inc=inc+5;
    setTimeout("move()",1) 
    } 
    } 
    //--> 
    </script>
    aDog

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2002
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thiers alot of little things you could do to clean up this function, but I just cant get into it right now. You should atleast remove the ((( document.getElementById('test').style.display='block' ))) and put it in its own function, (which you shouldn't call from the move function every time around)

  4. #4
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try something like...

    PHP Code:

    function move()
    {
        
    document.getElementById('test').style;

        if(
    pixelLeft<=pos)
        {
            
    x.display='block;
            x.pixelLeft=inc;
            x.inc=inc+5;
            x.setTimeout("move()",1);
        } 

    or
    PHP Code:

    function move()
    {
        
    with(document.getElementById('test').style);
        {
            if(
    pixelLeft<=pos)
            {
                
    display='block;
                pixelLeft=inc;
                inc=inc+5;
                setTimeout("move()",1);
            } 
        }

    im not sure which is faster, but i think the first one would be


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
  •