JQuery Accordion menu

Sunday Nov 25 2007

This post is here for historical / archival purposes. Comments are disabled. Please visit the link below for the latest version of the JQuery accordion.

Yup, yet another JQuery Accordion Plugin

This weekend I did a simple using . I figured it would be nice to share it on my blog as it may be useful to other people. I have no idea if this has already been done, if someone else has done a better job at it but... this one is mine! Feel free to use it if you need an accordion component on your (non commercial) website.

I whipped up a little demo page where you can see the menu in action and download the source. The menu will open with the first submenu expanded and items that don't contain a submenu will behave like regular links.

I didn't think I'd need to make this remark but: please don't be an asshole and do what these people from html.it did. Not with this, not with any of my other stuff, heck, not with anyone's stuff. It's just wrong. Thanks!

Source

  1. function initMenu() {
  2. $('#pagemenu ul').hide();
  3. $('#pagemenu ul:first').show();
  4. $('#pagemenu li a').click(
  5. function() {
  6. var checkElement = $(this).next();
  7. if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
  8. return false;
  9. }
  10. if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
  11. $('#pagemenu ul:visible').slideUp('normal');
  12. checkElement.slideDown('normal');
  13. return false;
  14. }
  15. }
  16. );
  17. }
  18. $(document).ready(function() {initMenu();});

Go to the demo page to take a look and download it if you like it.

small update: I added a version that acts as a simple collapsing menu. Even less code needed for that:

  1. function initMenu() {
  2. $('#menu ul').hide();
  3. $('#menu li a').click(
  4. function() {
  5. $(this).next().slideToggle('normal');
  6. }
  7. );
  8. }
  9. $(document).ready(function() {initMenu();});

Safari 3 weirdness update

In the comments a problem with Safari was described. I just tried the example page in the latest nightly build of Webkit and it's working fine. I guess it's therefore safe to assume we're dealing with a Safari 3 bug.

Dark Matter Pro: a premium photoblog template.

Affiliate program available

bookmarking

Commentary

Join the discussion! Leave a comment through the comment form below!

Got something to add to this?

Feel free to leave a comment on this site. You can use Textile and Emoticons. Your email address is only used to show a gravatar. Please stay on-topic and use common decency. Spammers will be shot in front of a live studio audience.

If you plan on posting code, use pastebin please and post a URL to the code. The comment processing doesn't deal very well with code. Sorry for the inconvenience.

Human comment spammers: don't bother posting your crap here. Comments are moderated and I won't let any of your shit through.

Trackbacks

If you have an interesting related post on your own site you can leave a trackback. As they say: 'a little AJAX a day keeps the spammers away' which is why you'll have to click below to generate a trackback key. The key will be valid for 15 minutes and can be used only once.

 

  • Featured Links
RockySomewhere near the Orion NebulaBookalicio.usGolden Gate BridgeThames River BankJackie and mePimpin' it