使用'X'图标关闭实体sidenav

时间:2016-07-15 03:41:37

标签: javascript php css wordpress materialize

我设计了我的sidenav以覆盖100%的屏幕宽度,并需要在右上角添加一个标准的“X”图标以关闭导航。它也适用于wordpress主题,所以也是如此。建议?

<nav class="transparent z-depth-0">
  <div class="nav-wrapper">
    <a href="<?php echo get_option('home'); ?>" class="brand-logo center-align"></a>

    <a href="#" data-activates="mobile-demo" class="right button-collapse" style="color: white;"><i class="material-icons">menu</i></a>

    <?php wp_nav_menu (array( 'theme_location'=>'primary', menu_class => 'right hide-on-med-and-down')); ?>


    <?php wp_nav_menu (array( 'theme_location'=>'primary', menu_class => 'side-nav', menu_id => 'mobile-demo')); ?>


  </div>

</nav>

编辑:所以这是关闭sidenav onclick

的功能
 // if closeOnClick, then add close event for all a tags in side sideNav
    if (options.closeOnClick === true) {
      menu_id.on("click.itemclick", "a:not(.collapsible-header)",      function(){
        removeMenu();
      });
    } 

基本上,如果close on click设置为true(如min),则当点击导航中的任何链接时,sidenav将关闭。基于此,我似乎需要添加此链接:

<a href="#"  class="right" style= "color: white;"><i class="material-icons">clear</i></a>

进入这个数组(上面代码中与sidenav相关的第二个:

<?php wp_nav_menu (array( 'theme_location'=>'primary', menu_class => 'side-nav', menu_id => 'mobile-demo')); ?>

到目前为止,我已经尝试过并且没有成功。

4 个答案:

答案 0 :(得分:0)

也许你可以使用jQuery fadeOut函数?

答案 1 :(得分:0)

好的,经过多次试验,错误和研究的答案是:

<nav class="transparent z-depth-0">
  <div class="nav-wrapper">
    <a href="<?php echo get_option('home'); ?>" class="brand-logo center- align"></a>

    <a href="#" data-activates="mobile-demo" class="right button-collapse" style="color: white;"><i class="material-icons">menu</i></a>

    <?php wp_nav_menu (array( 'theme_location'=>'primary', menu_class => 'right hide-on-med-and-down')); ?>


    <?php wp_nav_menu (array('theme_location' => 'primary', 'items_wrap' => my_nav_wrap(), )); ?>


  </div>

</nav>

并在functions.php中创建自定义nav_wrap:

function my_nav_wrap() {
    $wrap  = '<ul class="side-nav" id="mobile-demo">';
    $wrap .= '<li>';
    $wrap .= '<a href="#"  class="right" style= "color: white;">';
    $wrap .= '<i class="material-icons">clear</i>';
    $wrap .= '</a>';
    $wrap .= '</li>';
    $wrap .= '<div class="clear"></div>';
    $wrap .= '%3$s';
    $wrap .= '</ul>';

  return $wrap;
}

答案 2 :(得分:0)

只需添加一个类为sidenav-close的菜单项即可。

示例:

<li>
   <a href="#!" class="sidenav-close">Close </a>
</li>

答案 3 :(得分:0)

只需开发Metalbox答案

<div>
   <a href="#!" class="sidenav-close"><i class="material-icons">close</i></a>
</div>

然后是CSS

a.sidenav-close > i.material-icons {
    position: absolute;
    right:20px;
    top: 20px;
    color:black  
}