jQuery向下滑动功能无法在导航栏中实现

时间:2019-01-13 17:01:27

标签: jquery html css

我正在尝试创建一个导航栏。将鼠标悬停在其上时,下拉菜单应向下滑动。但就我而言,这没有发生。我先用css尝试过,但是没有用,然后我再次开始在jquery中做。它没有滑落,什么也没发生。有人可以指导我吗?这将带来巨大的帮助。

$(document).ready(function () {
 
  $(".nav-item").hover('hover', function () {
    var delayTime = 550;
    var $dropdown = $(this).next(".dropdrown");
    if($dropdown.is(':visible')){
      $dropdown.delay(delayTime).slideDown("slow");
    } else {
      $dropup.delay(delayTime).slideUp("slow");
    }
    $(".dropdown").hide();
  });

 

});
nav ul li a{
   line-height:59px;
  -webkit-transition: background-color 1s;
  -moz-transition: background-color 1s;
  -o-transition: background-color 1s;
  transition: background-color 1s;
}

nav .navbar-nav .nav-item .nav-link:hover, .dropdown:hover .dropbtn{
  background-color: #f1c575;
}

nav .navbar-nav .nav-item .nav-link {
  position: relative;
}

nav .navbar-nav .nav-item .nav-link:hover:after {
content: "";
display: block;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-bottom: 10px solid #7B8B93;
position: absolute;
left: 35%;
bottom: 0px;
}

/* Nav Menu Starts */

.dropdown-content {
  display: none;
  position: absolute;
  background-color: #7b8b93;
  width: 100%;
  left: 0;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
  z-index: 1;
  -webkit-transition: height 2s; /* For Safari 3.1 to 6.0 */
  transition: height 2s;
}

nav ul li .dropdown:hover .dropdown-content {
  display: block;
  height: 300px;
}

.dropdown{
  position: initial;
}


.nav-link:hover + .dropdown .dropdown-content{
  display: block;
}

/* Nav Menu  Ends*/
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">LoGo</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
    aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>

  <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav ml-auto">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Capabilities</a>
        <div class="dropdown">
          <div class="dropdown-content">
            <div class="row">
              <div class="col-lg-4">
                <h3 class="ml-3">Products</h3>
                <p class="ml-3"><a class="commerce" href="#">Dr.Commerce</a></p>
              </div>
              <div class="col-lg-8 services">
                <h3>Capabilities</h3>
                <ul class="list-inline">
                  <li class="list-inline-item">
                    <img src="./images/twitter-xxl.png" width="60" height="67" alt="New York">
                  </li>
                  <li class="list-inline-item">
                    <img src="./images/instagram-xxl.png" width="60" height="67" alt="New York">
                  </li>

                </ul>
              </div>
            </div>
          </div>
        </div>
      </li>
    </ul>
  </div>
</nav>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<script
  src="https://code.jquery.com/jquery-3.3.1.min.js"
  integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
  crossorigin="anonymous"></script>

1 个答案:

答案 0 :(得分:2)

使用$(".nav-item").hover( function () {

$(".nav-item").on('hover', function () { 悬停期望第一个参数是回调。