JQuery实现手风琴

JQuery实现手风琴小案例

提示 : jQuery线上地址
代码片段 :

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>手风琴</title>
  <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    .box {
      width: 500px;
      height: auto;
      margin: auto;
    }

    ul {
      list-style: none;
    }

    .outerUl>li {
      text-align: center;
      background-color: royalblue;
      border-bottom: 1px solid gray;
    }

    .outerUl>li:last-child {
      border-bottom: none;
    }

    .childUl>li {
      width: 100%;
      background-color: white;
      line-height: 40px;
    }

    .childUl {
      display: none;
    }

    h4 {
      padding: 8px 0;
    }
  </style>
</head>

<body>
  <div class="box">
    <ul class="outerUl">
      <li>
        <h4>软件教学</h4>
        <ul class="childUl">
          <li>java</li>
          <li>web前端</li>
          <li>安卓开发</li>
          <li>iOS开发</li>
        </ul>
      </li>
      <li>
        <h4>游戏动漫</h4>
        <ul class="childUl">
          <li>英雄联盟</li>
          <li>王者荣耀</li>
          <li>超级玛丽</li>
          <li>双截龙</li>
        </ul>
      </li>
      <li>
        <h4>电商企业</h4>
        <ul class="childUl">
          <li>淘宝</li>
          <li>天猫</li>
          <li>京东</li>
          <li>苏宁易购</li>
        </ul>
      </li>
      <li>
        <h4>营销培训</h4>
        <ul class="childUl">
          <li>seo</li>
          <li>微信营销</li>
          <li>网络创业</li>
          <li>市场营销</li>
        </ul>
      </li>
    </ul>
  </div>
</body>
<script>
  $('h4').click(function () {
    $(this).siblings().slideToggle(1000)
    $('.childUl').not($(this).next()).slideUp(1000)
  })
</script>

</html>

效果展示 :
打开后的页面

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值