jQuery在单击标题时上下滑动ul

托尼

对于我的页面,我的标题带有“ head”类。当我单击它们时,它们应该在它们下面显示ul类的“内容”,并且当单击新标题时,当前显示的列表消失,并且出现新标题的新列表。我记下了,但是说我单击标题1,它显示了列表1。当我再次单击它时,我需要将列表向上滑动,但我无法像这样。这是我到目前为止所拥有的:

<!DOCTYPE html>
<html lang="en">
<head>
<title>FV Runners</title>
<meta charset="UTF-8">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <link href="styles/normalize.css" rel="stylesheet" />
  <link href="styles/my_style.css" rel="stylesheet" />
  <script>
  $(document).ready(function(){
    $(".head").on("click", function(){
      $(".content").hide();
      $(this).next(".content").slideToggle();
    })
  })
  </script>
</head>
<body>
  <div id="header">
    <h1>Fox Valley Runners Club</h1>
  </div> <!-- End of 'header' div-->

  <div id="main">
  </div>  <!-- End of 'main' div-->

  <div id="pics">

    <div class="race_box">
      <img src="images/run1.jpg" /><br />
      <figcaption>5k/10k Events</figcaption>

      <div class=".races" id="5k">
        <h3>5k/10 Events</h3>
        <div>
          <h4 class="head">Mini Sprint</h4>
            <ul class="content">
              <li>10/30/20<br>Memorial Park<br>Appleton</li>
            </ul>
          <h4 class="head">Iron Horse</h4>
          <ul class="content">
            <li>11/06/20<br>Bay Beach Park<br>Green Bay</li>
          </ul>
          <h4 class="head">Twilight Trail</h4>
          <ul class="content">
            <li>11/13/20<br>>River's Edge Park<br>Wrightstown</li>
          </ul>
        </div>
      </div><!--  End of '5k' div-->
    </div> <!-- End of 'run1' div-->

    <div class="race_box">
      <img src="images/run2.jpg" /><br />
      <figcaption>Half Marathon Events</figcaption>

      <div class=".races" id="half">
        <h3>Half Marathon Events</h3>
        <div>
          <h4 class="head">Fox River Marathon</h4>
            <ul class="content">
              <li>10/15/20<br>Pierce Park<br>Appleton</li>
            </ul>
          <h4 class="head">N.E.W. Half Marathon</h4>
            <ul class="content">
              <li>10/29/20<br>Bay Beach Park<br>Green Bay</li>
            </ul>
          <h4 class="head">Winnebago Run</h4>
            <ul class="content">
              <li>11/27/20<br>Menominee Park<br>>Oshkosh</li>
            </ul>
        </div>
      </div> <!-- End of 'half' div-->
    </div><!-- End of 'run2' div-->

    <div class="race_box">
      <img src="images/run3.jpg" /><br />
      <figcaption>Full Marathon Events</figcaption>

      <div class=".races "id="full">
        <h3>Full Marathon Events</h3>
        <div>
          <h4 class="head">Cheesehead Marathon</h4>
            <ul class="content">
              <li>9/24/20<br>Pamperin Park<br>Green Bay</li>
            </ul>
          <h4 class="head">Chain O'Lakes Marathon</h4>
            <ul class="content">
              <li>10/29/20<br>Bay Beach Park<br>Green Bay</li>
            </ul>
          <h4 class="head">Fox Cities Marathon</h4>
            <ul class="content">
              <li>11/12/20<br>Menominee Park<br>>Oshkosh</li>
            </ul>
        </div>
      </div> <!-- End of 'full' div-->
    </div> <!-- End of 'run3' div-->

  </div> <!-- End of 'pics' div-->


</body>
</html>

单击同一标题时,我需要帮助来获取标题列表,该列表位于下方。

阿利·希克斯(Arleigh Hix)

您只需要从调用的选择中排除当前项目hidenot方法对此非常有效。

$(document).ready(function() {
  $(".head").on("click", function() {
    let $list = $(this).next(".content");
    $(".content").not($list).hide();
    $list.slideToggle();
  })
})
.content {
  display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<h4 class="head">Mini Sprint</h4>
<ul class="content">
  <li>10/30/20<br>Memorial Park<br>Appleton</li>
</ul>
<h4 class="head">Iron Horse</h4>
<ul class="content">
  <li>11/06/20<br>Bay Beach Park<br>Green Bay</li>
</ul>
<h4 class="head">Twilight Trail</h4>
<ul class="content">
  <li>11/13/20<br>>River's Edge Park<br>Wrightstown</li>
</ul>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

当单击标题时,当新列表向下滑动时,jQuery向上滑动显示列表?

来自分类Dev

jQuery单击时向下滑动

来自分类Dev

我在jquery上下滑动时遇到问题

来自分类Dev

jQuery 向下滑动 div - 单击回调时消失

来自分类Dev

jquery - 向下滑动每个父 ul

来自分类Dev

jQuery上下滑动功能延迟

来自分类Dev

jQuery个人列表上下滑动

来自分类Dev

单击选项卡时,可以平滑地上下滑动内容

来自分类Dev

上下滑动面板

来自分类Dev

jQuery-如何在单击时停止上/下滑动行为

来自分类Dev

悬停父div时使图像或div上下滑动

来自分类Dev

列出触摸时可上下滑动的UIViews列表

来自分类Dev

父级上下滑动时保持图像静止

来自分类Dev

CSS在悬停时在div上的图像上下滑动

来自分类Dev

当您单击链接时,向上和向下滑动

来自分类Dev

动画化固定标头以在单击时向下滑动

来自分类Dev

AngularJS-单击时向下滑动菜单

来自分类Dev

单击时,向下滑动div并更改按钮图标

来自分类Dev

嵌套div上下滑动

来自分类Dev

CSS过渡-上下滑动

来自分类Dev

如何使导航栏项目在悬停时向下滑动?(jQuery的)

来自分类Dev

如何在单击时切换 Slick 滑块(向下滑动并向上滑动)

来自分类Dev

如何在AngularJS中上下滑动?

来自分类Dev

ngAnimate上下滑动,高度不固定

来自分类Dev

li元素如何上下滑动?

来自分类Dev

ngAnimate上下滑动,高度不固定

来自分类Dev

jQuery向下滑动不向下滑动

来自分类Dev

当用户继续滚动时,在滚动页面上上下滑动div,而不会中断动画

来自分类Dev

切换时使菜单功能区与菜单一起上下滑动