SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member Good.Things's Avatar
    Join Date
    Apr 2007
    Location
    Texas, USA
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mm_menu and hiding recently made visible layers

    I'm working with this code which sets an object to visible when clicked. Trouble is the previous object hasn't been set to hidden so they overlap each other.

    How can I get this function to hide the previous object before showing the next ?

    Thanks

    Code:
    function MM_showHideLayers() { //v6.0
      var i,p,v,obj,args=MM_showHideLayers.arguments;
      for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
        if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='show')?'hidden':v; }
        obj.visibility=v; }
    This space left blank intentionally.

  2. #2
    SitePoint Evangelist pip's Avatar
    Join Date
    Jun 2001
    Location
    Cape Town, South Africa
    Posts
    548
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, just to support your requirements, I need some direction here.

    Will only one of the objects be visible at a time? In this case, you can create a temp variable which will be assigned to the object that is visible, and you will need to add one line of code to your function. But if the functionality of this script is going beyond that, we will need to slightly re-invent the wheel here.

    Basically, this function allows you to pass it a number of arguments. Based on how it reads the arguments passed to it, it sets the "v" to "show" if you want to make an object visible. How you're using this function is the key to what you need to do. So if you want to look into the way you're using it, and try to do it properly, then we can do that, otherwise we can go the route explained in my first paragraph.
    - Pip
    ---------------------------------------------------------------------------------
    Nothing takes the taste out of peanut butter quite like unrequited love.

  3. #3
    SitePoint Member Good.Things's Avatar
    Join Date
    Apr 2007
    Location
    Texas, USA
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Thanks for your reply.

    Yes, I only want 1 object to be visible at a time. Here is the page in question
    Code:
    http://tinyurl.com/yvlvmn
    The effect I'm looking for is this :

    1. Click first area, layer gets raised.
    2. Click different area, first layer gets hidden, other layer gets raised.

    Right now I'm getting :

    1. Click first area, layer gets raised.
    2. Click different area, first layer stays raised and other layer over laps it.

    Thanks
    This space left blank intentionally.

  4. #4
    SitePoint Evangelist pip's Avatar
    Join Date
    Jun 2001
    Location
    Cape Town, South Africa
    Posts
    548
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try changing the function to the following:

    Code:
    var oVisibleObject = null;
    function MM_showHideLayers() { //v6.0
        if (oVisibleObject)
            oVisibleObject.style.visibility = "hidden";
    
        var i,p,v,obj,args=MM_showHideLayers.arguments;
        for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) {
            oVisibleObject = obj;
            v=args[i+2];
            if (obj.style) {
                obj=obj.style;
                v=(v=='show')?'visible':(v=='show')?'hidden':v;
            }
            obj.visibility=v;
        }
    }
    I haven't actually tested it, because I don't have the same page content as you. If it doesn't work, I'll try to create a page that shows and hides elements like yours, but I'm almost sure that'll do the trick.

    Let me know.
    - Pip
    ---------------------------------------------------------------------------------
    Nothing takes the taste out of peanut butter quite like unrequited love.

  5. #5
    SitePoint Member Good.Things's Avatar
    Join Date
    Apr 2007
    Location
    Texas, USA
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're awesome, that worked perfectly.
    This space left blank intentionally.

  6. #6
    SitePoint Evangelist pip's Avatar
    Join Date
    Jun 2001
    Location
    Cape Town, South Africa
    Posts
    548
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Glad I could be of assistance. ;O)
    - Pip
    ---------------------------------------------------------------------------------
    Nothing takes the taste out of peanut butter quite like unrequited love.


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
  •