SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast vek's Avatar
    Join Date
    Jun 2004
    Location
    Florence, KY
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question setTimeout on Mac doesn't seem to be working

    I have no way of testing this, did this for a friend. He uses a Mac so he just told me it doesn't work. I have tried modifying it and don't want to wait all day for him to get out of classes so, does anyone see why the menu won't hide after 1 second. He did the website, I'm just working on the menu for him.
    http://zerovektor.com/tmp/
    http://zerovektor.com/tmp/smenu.js
    http://zerovektor.com/tmp/smenu.css

    I read something about Mac IE not liking () on function calls inside the setTimeout function, but I was trying to pass a parameter.

    ----
    Also, if someone could tell me using Safari if the menu jumps to the top left of the screen insted of appearing next to the menu you moused over? I think I figured out what could be causing that, but have no way of testing it.

    Thanks!
    Last edited by vek; Feb 3, 2005 at 09:15.

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    d isn't in scope when the setTimeout() executes. setTimeout() executes at global scope so it can't see any local variables.

  3. #3
    SitePoint Enthusiast vek's Avatar
    Join Date
    Jun 2004
    Location
    Florence, KY
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so would something like this work instead?
    Code:
    window.onload=show;
    
    var hideTimeout = null;
    var numberMenus = 14;
    var timeout = 1000;
    var elementToHide = null;
    
    function show(id, left, top)
    {
        var d = document.getElementById(id);
        
    	for(var i = 1; i <= numberMenus; i++)
        {
            if(document.getElementById('smenu' + i) && (('smenu' + i) !=  id))
            {
                document.getElementById('smenu' + i).style.display='none';
            }
        }
        
        if(hideTimeout)
        {
            clearTimeout(hideTimeout);
            hideTimeout = null;
            elementToHide = null;
        }
        
        if(d)
        {
            d.style.display='block';
            d.style.left=left;
            d.style.top=top;
        }
    }
    
    function hide(id)
    {
        var d = document.getElementById(id);
        
        if(d)
        {
            elementToHide = d;
            hideTimeout = setTimeout(function(){delay_hide();}, timeout);
        }
    }
    
    function delay_hide()
    {
        elementToHide.style.display='none';
    }

  4. #4
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I read something about Mac IE not liking () on function calls inside the setTimeout function,
    Nope, right the opposite. I don't have a Mac, but I don't think IE/Mac supports passing a function reference as the first arg to setTimeout.

  5. #5
    SitePoint Enthusiast vek's Avatar
    Join Date
    Jun 2004
    Location
    Florence, KY
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So, I should just do it like this then?

    hideTimeout = setTimeout("delay_hide()", timeout);

  6. #6
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    var elementToHide = null;
    var timeout = 1000;
    ...
    ...
    function hide(id)
    {
        var d = document.getElementById(id);
        
        if(d)
        {
            elementToHide = d;
            hideTimeout = setTimeout(function(){delay_hide();}, timeout);
        }
    }
    The setting of the setTimeout() occurs at local scope--it's only the execution of the function specified that occurs at global scope, so the variable 'timeout' doesn't need to be a global variable. However, not hard coding the timing and making it a global variable at the top of the file is a nice touch.

    So, I should just do it like this then?

    hideTimeout = setTimeout("delay_hide()", timeout);
    Does it work?

  7. #7
    SitePoint Enthusiast vek's Avatar
    Join Date
    Jun 2004
    Location
    Florence, KY
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by 7stud
    Does it work?
    I don't know yet. I don't have a Mac to test it on. Have to wait for someone else to test it for me.

  8. #8
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    did this for a friend. He uses a Mac so he just told me it doesn't work.
    Try that person.

  9. #9
    SitePoint Enthusiast vek's Avatar
    Join Date
    Jun 2004
    Location
    Florence, KY
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, he was finally online some before he went to work this morning so we were able to pass screen shots and get everything working. Changing that from a function pointer to just the function call and everything made it work. The menu now looks the same and works the same on IE6, Opera 7, Firefox 1.0, Safari, IE Mac, and Konqueror.

  10. #10
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


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
  •