Javascript下拉菜单无效

时间:2015-09-28 05:50:19

标签: javascript drop-down-menu menu

我正在尝试创建下拉菜单,当点击“mobile-nav”按钮时,该菜单会打开并折叠。

请将此视频或网站视为预期行为的示例:

function mobileNav() {
  $('.mobile-nav-toggle').on('click', function() {
    var status = $(this).hasClass('is-open');
    if (status) {
      $('.mobile-nav-toggle, .mobile-nav').removeClass('is-open');
    } else {
      $('.mobile-nav-toggle, .mobile-nav').addClass('is-open');
    }
  });
}
/* ------------------------------------------ */

/* BASIC SETUP */

/* ------------------------------------------ */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
html,
body {
  text-align: justify color: #fff;
  font-family: 'Lato', 'arial', sans-serif;
  font-size: 19px;
  font-weight: 400;
  text-rendering: optimizeLegibility;
  background: #333;
  background-position: center;
  height: 100vh;
  background-attachment: fixed;
}
/* ------------------------------------------ */

/* REUSABLE COMPONENTS */

/* ------------------------------------------ */

.row-basic {
  max-width: 1216px;
}
.main-container {
  max-width: 1216px;
  margin: 0 auto;
}
/* ------------------------------------------ */

/* HEADER */

/* ------------------------------------------ */

.mobile-nav {
  display: ;
  position: ;
  width: 1216px;
  background: white;
  padding: 31px 0px 21px;
  transform: translateY(-100%);
  transition: all 0.3s ease-in-out
}
.mobile-nav.is-open {
  display: block;
  transform: translateY(0%);
}
.mobile-nav ul {
  list-style: none;
}
.mobile-nav ul li {
  text-align: center;
  margin-bottom: 10px;
}
.mobile-nav ul li a:link,
.mobile-nav ul li a:visited {
  color: #999;
  text-decoration: none;
  text-transform: uppercase;
}
header {
  background-color: rgba(246, 149, 149, 0.06);
  height: 81px;
  width: auto;
  padding-top: 24px;
  margin-top: 26px;
  margin-bottom: 0px;
  display: flex;
  justify-content: space-between;
}
/* ----- NAVIGATION -----*/

nav {
  display: flex;
  align-items: center;
}
nav ul {
  display: flex;
}
.main-nav {
  list-style: none;
}
.main-nav li {
  display: inline-block;
  line-height: 31px;
  border-right: 1px solid rgba(255, 255, 255, 0.24);
  padding-right: 9px;
  padding-left: 9px;
  margin-right: 0px;
  width: auto;
}
.main-nav li:last-child {
  border-right: hidden;
  margin-right: 31px;
}
.main-nav li a:link,
.main-nav li a:visited {
  color: #fff;
  text-decoration: none;
  text-transform: uppercase;
}
.user-tools {
  display: flex;
  align-items: center;
}
.user-tools:focus {
  outline: none;
}
/* ----- MENU BUTTON -----*/

.mobile-nav-toggle {
  height: 50px;
  width: 35px;
  margin-right: 31px;
  display: flex;
  align-items: center;
  cursor: pointer;
}
.mobile-nav-toggle span,
.mobile-nav-toggle span::before,
.mobile-nav-toggle span::after {
  border-radius: 2px;
  content: "";
  display: block;
  height: 6px;
  width: 100%;
  background: #fff;
  position: relative;
}
.mobile-nav-toggle span::before {
  top: 11px;
}
.mobile-nav-toggle span::after {
  bottom: 17px;
}
<html lang="en">

<head>

  <link rel="stylesheet" type="text/css" href="resources/css/style.css">
  <link href='https://fonts.googleapis.com/css?family=Lato:400,900' rel='stylesheet' type='text/css'>
  <script src="resources/js/functions.js"></script>

</head>

<body>
  <div class="main-container">
    <div class="mobile-nav is-open">
      <ul>
        <li><a href="#">Menu</a>
        </li>
        <li><a href="#">Services</a>
        </li>
        <li><a href="#">Gallery</a>
        </li>
        <li><a href="#">About Me</a>
        </li>
      </ul>
    </div>
    <header class="row-basic">
      <nav>
        <ul class="main-nav">
          <li><a href="#">Menu</a>
          </li>
          <li><a href="#">Services</a>
          </li>
          <li><a href="#">Gallery</a>
          </li>
          <li><a href="#">About Me</a>
          </li>
        </ul>
      </nav>
      <div class="user-tools">
        <div class="mobile-nav-toggle">
          <span></span>
        </div>
      </div>
    </header>
  </div>
</body>

</html>

1 个答案:

答案 0 :(得分:1)

  1. 您必须添加指向jQuery脚本的链接。
  2. 删除声明功能mobileNav(){并关闭braket}。

    SELECT a.id, b.color 
    FROM GUYS a 
    LEFT JOIN SHIRT b 
    ON a.ID=b.GUYS_ID AND b.color='red' 
    ORDER BY a.id ASC;
    
  3. 以下是工作代码https://jsfiddle.net/efjz40ob/

    的示例