www.webdeveloper.com
Results 1 to 2 of 2

Thread: Toggling pure-menu

  1. #1
    Join Date
    Aug 2014
    Posts
    14

    Toggling pure-menu

    Hey,
    So I used Purecss to make a vertical menu:
    Code:
    						
    								<div class="pure-menu" id="pmenu">
    								<a class="pure-menu-heading" id="m_inc" href="" >INC</a>
    									
    								<ul>
    									<li><a href="#" id="m_ms">Microsoft</a></li>
    									<li><a href="#" id="m_apple">Apple</a></li>
    									<li><a href="#" id="m_lenovo">Lenovo</a></li>
    									<li><a href="#" id="m_sony">Sony</a></li>
    									<li><a href="#" id="m_hp">HP</a></li>
    								</ul>
    						</div>
    And I'm trying to use jQuery to make a simple program that opens/closes it when you click the header:
    Code:
    $(document).ready(function(){
    
    	$('#m_inc').click(function(){
    		$('#pmenu').toggleClass("pure-menu-open");
    	});
    	
    });
    At first I thought that nothing is happening when I click but then, I added an alert right under:
    Code:
    alert ($('#pmenu').attr('class'));
    This is what happens:
    http://prntscr.com/4e2pk3
    But as soon as I close the alert window, the menu closes back again.
    I've no idea why this is happening but it makes no sense.. I mean it shows that the menu element indeed has "pure-menu-open" class.
    Any ideas?

    PS: If you don't know about pure-menus:
    http://purecss.io/menus/

    Thanks in advance

  2. #2
    Join Date
    Feb 2014
    Location
    Managua, Nicaragua
    Posts
    45
    Code:
    <div class="pure-menu" id="pmenu">
    <ul>
    <li>
    	<a class="pure-menu-heading" id="m_inc" href="" >INC</a>
    	<ul>
    		<li><a href="#" id="m_ms">Microsoft</a></li>
    		<li><a href="#" id="m_apple">Apple</a></li>
    		<li><a href="#" id="m_lenovo">Lenovo</a></li>
    		<li><a href="#" id="m_sony">Sony</a></li>
    		<li><a href="#" id="m_hp">HP</a></li>
    	</ul>
    </li>
    </ul>
    </div>
    First, use a ul tag or a nav tag to group al li elements, then gruop the a tag and the li tags into a li tag parent. Hide the ul tag with css...

    If you want to work only with css
    Code:
    #pmenu a.pure-menu-heading:hover ul{display:block;}
    jQuery
    Code:
    jQuery('body').on('click', '#pmenu a.pure-menu-heading', function(){
    jQuery(this).next('ul').slideToggle();
    });
    Hope that helps

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles