SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Member
    Join Date
    Dec 2013
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy jQuery Menu Help

    Hello,

    I'm very new to javascipt/jQuery but have put together this menu

    http://jsfiddle.net/Dnamixup/pHgB7/3/

    I've got it to keep the menu items open when you change page but I need the menu to stay open when you've clicked a sub-menu item as it currently closes it.

    Any ideas?

    Thank you

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    6,002
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Hi there,

    Ideally, you should not be using JavaScript to remember a navigation's state.

    How are youincluing the navigation into your page?
    Via PHP or is it hard-coded?

  3. #3
    SitePoint Member
    Join Date
    Dec 2013
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The navigation is hard coded into the page.

    Is there another way to remember a navigation state? WOuld it be with css?

  4. #4
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    6,002
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Quote Originally Posted by Dnamixup View Post
    Is there another way to remember a navigation state? WOuld it be with css?
    Exactly.
    I've made you a simple example demonstrating how to do this.
    You basically apply an "active" class to your active menu points and style them differently than your non-active ones.

    Have a look at the source of my demo to see the code and let me know if you have any questions.

    HTH

  5. #5
    SitePoint Member
    Join Date
    Dec 2013
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you very much for the demo, it's a good piece of code to work from!

    So the jQuery is just running the menu animations?

    Would it be possible to keep the menu open say when I click Page 1?

    Thanks again!

  6. #6
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    6,002
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Quote Originally Posted by Dnamixup View Post
    So the jQuery is just running the menu animations?
    That's right.
    HTTP is a stateless protocol, so individual web pages (and by definition the JS they execute) have no concept of an action which was taken on a previous/different page.
    You can use client-side storage to persist data, but in this case, it is better to just apply a class and style accordingly.

    Quote Originally Posted by Dnamixup View Post
    Would it be possible to keep the menu open say when I click Page 1?
    Yes, you could add the appropriate class declaration to page 1 (look at the source code of the demo).
    However, if this is something you want to do, then I would alter the class names for example "open" is better than "active".

  7. #7
    SitePoint Member
    Join Date
    Dec 2013
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Brilliant! You've been a great help!

    I'm going to have a play around with the source code and see what I can come up with!

    I'd +rep you but doesn't seem this forum uses it!

    Thanks again!

  8. #8
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    6,002
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Hi,

    No problem

    Quote Originally Posted by Dnamixup View Post
    I'd +rep you but doesn't seem this forum uses it!
    This has been discussed and will actually be introduced sometime in the future.
    In the meantime, you could show your appreciation by voting at the end of year awards which should be going live next week.

  9. #9
    SitePoint Member
    Join Date
    Dec 2013
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well I'll vote for you in the awards then

    Thanks again!


Tags for this Thread

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
  •