随笔 - 83  文章 - 1 评论 - 24 阅读 - 23250
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

<style>
  *{
   margin: 0;
   padding: 0;
  }
  .box{
    position: relative;
    width: 600px;
    height: 400px;
    margin: 100px auto;
    background: wheat;
  }
  .box li{
    float: left;
    line-height: 30px;
    padding: 0 20px;
    cursor: pointer;
    margin-left: 50px;
    background: pink;
    list-style: none;
    border-bottom: 1px solid pink;
  }
  .box .cur{
    background: yellow;
    color: white;
  }
  .box ul{
    height: 50px;
  }
  .box .d{
    position: absolute;
    left: 0;
    top: 40px;
    width: 600px;
    height: 400px;
  }
</style>
<body>
  <div class="box" id="b">
    <ul>
      <li class="cur">1</li>
      <li>2</li>
      <li>3</li>
      <li>4</li>
      <li>5</li>
    </ul>
     <div class="d" style="background: pink;"></div>
     <div class="d" style="background: yellow;"></div>
     <div class="d" style="background: blue;"></div>
     <div class="d" style="background: red;"></div>
     <div class="d" style="background: hotpink;"></div>
  </div>

  <script>
    // 下方展示下标为1的,其他的.d兄弟元素隐藏
    $('#b .d').eq(0).show().siblings('.d').hide();
    //点击标题,当前标题添加样式,其它兄弟元素取消样式  
    $('#b li').click(function(){
      $(this).addClass('cur').siblings().removeClass('cur');
      var i = $(this).index(); //点击当前元素的下标值
      $('#b .d').eq(i).show().siblings('.d').hide();
    });
  </script>

</body>

最终实现的效果如下:

posted on   是程序喵哇  阅读(19)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具
点击右上角即可分享
微信分享提示