SorryEh
SorryEh

Reputation: 928

How to make the drop down portion of my menu toggle in mobile view?

I have a menu where in desktop view a drop down effect works when you hover over it (Quick Links and Getting Started).

What I wanted to do was create a click-toggle version in mobile view, so when a user taps on Quick links for example, the menu expands with the additional links, and then tap again to close.

I know that in bootstrap (which I am using in my website) I can make it work similar, when the user taps on it the menu drops down, however what happens is the menu overlays over the others, i was hoping to just make it expand and push the others down instead.

I am also calling jquery version 1.12, and will be using all my jquery documents externally.

here is the JS Fiddle:

JsFiddle

HTML:

 <ul class="top-level-menu">
   <li>
      <a href="javascript:;">Quick Links</a>
      <ul class="second-level-menu">
         <li><a href="TR/Events/General?pg=informational&fr_id=[[S334:fr_id]]&type=fr_informational&sid=10353">About the program</a></li>
         <li><a href="TR/Events/General?pg=informational&fr_id=[[S334:fr_id]]&type=fr_informational&sid=10357">FAQs</a></li>
         <li><a href="TR/Events/General?pg=informational&fr_id=[[S334:fr_id]]&type=fr_informational&sid=10369">About the Society</a></li>
         <li><a href="TR/Events/General?pg=informational&fr_id=[[S334:fr_id]]&type=fr_informational&sid=10366">Where your money goes</a></li>
      </ul>
   </li>
   <li>
      <a href="javascript:;">Get Started</a>
      <ul class="second-level-menu">
         <li><a href="TRR/UnitFundraisingEvent/UFE_ON_odd_?fr_tm_opt=new&pg=tfind&fr_id=[[S334:fr_id]]">Create a fundraiser</a></li>
         <li><a href="TRR/UnitFundraisingEvent/UFE_ON_odd_?pg=tfind&fr_id=[[S334:fr_id]]&fr_tm_opt=existing">Join a fundraiser</a></li>
         <li><a href="TRR/UnitFundraisingEvent/UFE_ON_odd_?pg=tfind&fr_id=[[S334:fr_id]]&fr_tm_opt=none">Participate as an Individual<br />individal</a></li>
         <li><a href="TR/UnitFundraisingEvent/General?pg=pfind&fr_id=[[S334:fr_id]]">Pledge a participant<br />or fundraiser</a></li>
         <li><a href="Donation2?df_id=[[S42:0:form-id]]&PROXY_ID=[[S334:fr_id]]&PROXY_TYPE=21&FR_ID=[[S334:fr_id]]">Donate now</a></li>
      </ul>
   </li>
   <li>
      <a href="http://convio.cancer.ca/site/TR?type=fr_informational&pg=informational&fr_id=22046&sid=10364">Fundraising Tips</a>
   </li>
   <li>
      <a href="http://convio.cancer.ca/site/TR?type=fr_informational&pg=informational&fr_id=22046&sid=10356">Fundraising Ideas</a>
   </li>
   <li>
      <a href="http://convio.cancer.ca/site/TR?type=fr_informational&pg=informational&fr_id=22046&sid=10365">Promotion Tips</a>
   </li>
   <li>
      <a href="http://convio.cancer.ca/site/TR?type=fr_informational&pg=informational&fr_id=22046&sid=10360">Your Company</a>
   </li>
   <li>
      <a href="http://convio.cancer.ca/site/TR?type=fr_informational&pg=informational&fr_id=22046&sid=10355">Contact Us</a>
   </li>
</ul>

CSS:

.third-level-menu{

    position: absolute;
    top: 0;
    right: -150px;
    width: 150px;
    list-style: none;
    padding: 0;
    margin: 0;
    display: none;
}

.third-level-menu > li {

    height: 30px;
    background: #dff8fe;
}

.third-level-menu > li:hover { 
    background: #CCCCCC; 

}

.second-level-menu {

    position: absolute;
    top: 30px;
    left: 0;
    width: 300px;
    list-style: none;
    padding: 0;
    margin: 0;
    display: none;
}

.second-level-menu > li {

    position: relative;
    height: 30px;
    background: #dff8fe;
}

.second-level-menu > li:hover {

    background: #ffec9a; 

}

.top-level-menu {

    list-style: none;
    padding: 0;
    margin: 0;
}

.top-level-menu > li {

    position: relative;
    float: left;
    height: 30px;
    width: 133px;
    background: #ecf0f1;
}

.top-level-menu > li:hover { 

    background: #FFEE00; 
}

.top-level-menu li:hover > ul {

    /* On hover, display the next level's menu */
    display: inline;
}


/* Menu Link Styles */

.top-level-menu a /* Apply to all links inside the multi-level menu */
{
    font: bold 12px Arial, Helvetica, sans-serif;
    color: #000;
    text-decoration: none;
    padding: 0 0 0 10px;

    /* Make the link cover the entire list item-container */
    display: block;
    line-height: 30px;
}

.top-level-menu a:hover { 

    color: #000; 
}


@media screen and (max-width: 768px) {

   .top-level-menu > li {
      width: 100%;
    }


}

Upvotes: 0

Views: 51

Answers (1)

Rachel S
Rachel S

Reputation: 3920

In Bootstrap you can use an accordion menu for mobile. It will push the other things down when you open a menu option.

http://getbootstrap.com/javascript/#collapse-example-accordion

Upvotes: 1

Related Questions