Superfish - On click in the submenu remain open


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. $(function(){
  2. var menu = $("#nav");
  3.  
  4. menu.find("ul.sf-menu")
  5. .superfish({
  6. delay: 0,
  7. speed: 'fast',
  8. autoArrows: false,
  9. dropShadows: false,
  10. onHide: function(){
  11. if (this.parent().is('.sfPersist')) {
  12. this.show().css('visibility','visible').parent().addClass('sfHover');
  13. }
  14. }
  15. })
  16. .find('li > ul > li').click(function(){
  17. // hide previously persistent children (LOL that just sounds wrong)
  18. menu.find('.sfPersist')
  19. .removeClass('sfPersist sfHover')
  20. .find('> ul').hide().css('visibility','hidden');
  21.  
  22. // add children that should be persistent
  23. if ($(this).is('.sfSelected')) {
  24. // if previously selected, keep hidden
  25. menu.find('li.sfSelected').removeClass('sfSelected');
  26. } else {
  27. // Hide other selected classes
  28. menu.find('li.sfSelected').removeClass('sfSelected');
  29. // if newly selected, then show
  30. $(this)
  31. .addClass('sfSelected') // remember which one is selected
  32. .parent()
  33. .show().css('visibility','visible')
  34. .parent().addClass('sfHover sfPersist');
  35. }
  36. });
  37. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.