Accordion-Style Left Navigation Using jQuery and CSS in SharePoint 2010

Posted: November 7, 2014 in SharePoint2010

Introduction

All the Quick Link menus provided by SharePoint2010 out of the box have a fixed format and altering its CSS alters its branding. Implementing collapsible headings in the quick launch for SharePoint 2010 (jQuery UI accordion effect) would solve this issue. All the solutions that I’ve seen are for sites and sub sites. In the site navigation settings, I have entered a heading with links to site pages under it.

My current navigation works fine. For example if a category is open it will remain open until the category is clicked on. I implement an accordion on SharePoint current navigation.

However we can do collapsing and expanding functionality using:

  • jQuery
  • CSS

jQuery

If you want the accordion-style menu for all pages, you should work it into the v4.master.

You need to add the following code into the v4.master.

To edit, open the v4.master in SharePoint Designer 2010, share this piece of code to obtain an accordion style quick launch in SharePoint 2010.

  1. <script type=“text/javascript” src=http://ajax.Microsoft.com/ajax/jQuery/jquery-1.7.1.min.js&#8221;>
  2. <script type=“text/javascript”>
  3. $(function($) {
  4.  //Hide all
  5.  $(‘.s4-ql li ul’).hide();
  6.  //Set the Images up
  7.  var Collapse = “/_layouts/images/collapse.gif”;
  8.  var Expand = “/_layouts/images/expand.gif”;
  9.  //Find each top level UI and add reletive buttons & children numbers
  10.  $(‘.s4-ql ul li’).find(‘ul’).each(function(index) {
  11.  var $this = $(this);
  12.  $this.parent().find(‘a:first .menu-item-text’).parent().parent().parent().prepend([‘<a class=\’min\’ style=\’float:right; margin-left:5px;margin-top:6px;margin-right:5px;\’><img src=\’/_layouts/images/expand.gif\’/></a>’].join());
  13.  });
  14.  //Setup Click Hanlder
  15.  $(‘.min’).click(function() {
  16.  //Get Reference to img
  17.  var img = $(this).children();
  18.  //Traverse the DOM to find the child UL node
  19.  var subList = $(this).siblings(‘ul’);
  20.  //Check the visibility of the item and set the image
  21.  var Visibility = subList.is(“:visible”)? img.attr(‘src’,Expand) : img.attr(‘src’,Collapse);;
  22.  //Toggle the UL
  23.  subList.slideToggle();
  24.  });
  25.  });
  26. </script>

sharepoint home page

CSS

It is possible to do it with pure CSS. When it comes to SharePoint there is only one caveat; you can create a CSS with only an accordion menu as long as the accordion effect fires on hover and not when the navigation header is clicked.

Add the following CSS into the v4.master:

To edit, open the v4.master in SharePoint Designer 2010.

  1. <style>
  2.         .s4-ql li.static
  3.         {
  4.             height2em;
  5.             overflowhidden;
  6.         }
  7.         .s4-ql li.static:hover
  8.         {
  9.             heightauto;
  10.         }
  11.         .s4-ql li > span.menu-item
  12.         {
  13.             cursorpointer;
  14.         }
  15.         /* Format the headers */
  16.         .s4-ql li > span.menu-item
  17.         {
  18.             cursorpointer;
  19.             background#0171C6;
  20.             colorwhite;
  21.             bordersolid #fff;
  22.             border-width1px 0;
  23.         }
  24.         /* Format the accordion list items */
  25.         .s4-ql a.menu-item
  26.         {
  27.             color#000;
  28.             background#C9D4FF;
  29.             border1px solid #97C8F7;
  30.             border-bottomnone;
  31.         }
  32.         /* Format the header hover, list item hover and currently selected item */
  33.         .s4-ql li > span.menu-item:hover, /*Header */
  34.         .s4-ql a.selected, /* Selected */
  35.         .s4-ql a.menu-item:hover /* List item */
  36.         {
  37.             color#FFF;
  38.             background#073D7D;
  39.         }
  40.         .s4-ql ul.root > li.static
  41.         {
  42.             max-height2em;
  43.             overflowhidden;
  44.             transition: max-height 1s linear;
  45.         }
  46.        .s4-ql ul.root > li.static:hover
  47.        {
  48.             max-height500px;
  49.        }
  50.     </style>

category option in sharepoint

Summary

As described in this article, there are two ways to implement an accordion in SharePoint 2010 (Current Left Navigation).

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s