物化侧导航链接不起作用

时间:2017-02-19 01:02:20

标签: javascript html css materialize

我正在使用materializecss创建一个网站,但是我在侧面导航栏上添加的链接不起作用,我可以用它做什么,

当我点击链接时,侧面导航关闭 的

<div class="navbar-fixed">
    <nav>
        <div class="nav-wrapper">
            <a href="#" data-activates="mobile-demo" class="button-collapse"><i class="material-icons">menu</i></a>
            <a href="index.php" class="brand-logo left thin" title="bcgraphixx">Page Title</a>
            <ul class="right hide-on-med-and-down">
                <li><a class="waves-effect" href="index.php">Home</a></li>
                <li><a class="waves-effect" href="about-us.php">About us</a></li>
                <li><a class="waves-effect" href="services.php">Services</a></li>
                <li><a class="waves-effect" href="book.php">booking</a></li>
            </ul>

            <ul class="side-nav" id="mobile-demo">
                <li>
                    <div class="userView">
                        <div class="background">
                            <img src="<?php echo $srcurl; ?>/cover.png">
                        </div>
                        <a href="#!admin"><img class="circle" src="<?php echo $srcurl; ?>/logo.png"></a>
                        <a href="#!bcgraphix" title="bcgraphixTemplate"><span class="black-text name">DIGINEWS</span></a>

                    </div>
                </li>

                <li><a href="##"><center>MENU</center></a></li>
                <li><a class="waves-effect" href="index.php">Home</a></li>
                <li><a class="waves-effect" href="about-us.php">About us</a></li>
                <li><a class="waves-effect" href="services.php">Services</a></li>
                <li><a class="waves-effect" href="book.php">booking</a></li>
            </ul>

            <script>  $(".button-collapse").sideNav(); </script>
        </div>

    </nav>
</div>

2 个答案:

答案 0 :(得分:3)

  1. documentReady个事件中包含sideNav的JS代码,并将参数closeOnClick设置为true

  2. 将您的旁边菜单(带有“side-nav”类的ul元素)放在与navbar-fixed类相同的div级别。这是为了避免叠加的已知问题。请参阅this stackoverflow question and accepted answer

  3. $( document ).ready(function(){
    $('.button-collapse').sideNav({
          closeOnClick: true
        }
      );
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.0/css/materialize.min.css" rel="stylesheet"/>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.0/js/materialize.min.js"></script>
    
    <div class="navbar-fixed">
        <nav>
            <div class="nav-wrapper">
                <a href="#" data-activates="mobile-demo" class="button-collapse"><i class="material-icons">menu</i></a>
                <a href="#" class="brand-logo right thin" title="bcgraphixx">Page Title</a>
                <ul class="right hide-on-med-and-down">
                    <li><a class="waves-effect" href="#">Home</a></li>
                    <li><a class="waves-effect" href="#">About us</a></li>
                </ul>
            </div>
        </nav>
    </div>
    <ul class="side-nav" id="mobile-demo">
       <li><a href="##"><center>MENU</center></a></li>
       <li><a class="waves-effect" href="#!">Home</a></li>
       <li><a class="waves-effect" href="#!">About us</a></li>
    </ul>

答案 1 :(得分:0)

下面是简单的代码。...
您需要添加实现化sc,js和jquery js的CDN
这是您的固定导航栏

      <div class="navbar-fixed">
        <nav class="nav-wrapper">
          <div class="container">
            <a href="" class="brand-logo">Picnic.lk</a>
            <a href="" class="sidenav-trigger" data-target="mobile-menu">
              <i class="material-icons">menu</i>
            </a>
            <ul class="hide-on-med-and-down right">
              <li><a href="#photos">Photos</a></li>
              <li><a href="#services">Services</a></li>
              <li><a href="#contact">Contacts</a></li>
            </ul>
           </div>
         </nav>
       </div>

您的移动导航栏(侧面导航)

<ul class="sidenav grey lighten-2" id="mobile-menu">
    <li><a class="sidenav-close" href="#photos">Photos</a></li>
    <li><a class="sidenav-close" href="#services">Services</a></li>
    <li><a class="sidenav-close" href="#contact">Contacts</a></li>
</ul>

在下面的js代码中添加

<script>
 $(document).ready(function(){
    //side navigation
    $('.sidenav').sidenav({
        //your additional code goes here
    });
 });