jQuery写选项卡

<!DOCTYPE html>

<htmllang="en">

<head>

<metacharset="UTF-8"><title>choseCart</title>

<script src="https://cdn.bootcss.com/jquery/1.8.3/jquery.js"></script>

<styletype="text/css">

  *{margin: 0;padding: 0;}

  li{list-style: none;}

  #menu {height: 30px;}

  #menu li{float: left;background: #999;color: #fff;cursor: pointer;border:2px solid #666;}

  #menu .active{border-right-color: #666;border-left-color: #666;border-top-color: blue;border-bottom-color: #fff}

  #pannel div:nth-of-type(1){background: green;width: 335px;height: 200px;}

  #pannel div:nth-of-type(2){background: blue;width: 335px;height: 200px;}

  #pannel div:nth-of-type(3){background: black;width: 335px;height: 200px;}

  #pannel div:nth-of-type(4){background: red;width: 335px;height: 200px;}

  #pannel div{display: none;}

  #pannel .active{display: block;}

</style><scripttype="text/javascript">

 

  $(function(){

    let oLi=$('#menu li');

    /*oLi.bind('click',function() {

      let iIndex=$(this).index();oLi.removeClass('active').eq(iIndex).addClass('active');

      $('#pannel div').removeClass('active').eq(iIndex).addClass('active');

    });*/

  oLi.hover(function(){

    let iIndex=$(this).index();

    oLi.removeClass('active').eq(iIndex).addClass('active');

    $('#pannel div').removeClass('active').eq(iIndex).addClass('active');

    })

  })

</script>

</head>

<body>

  <div id="box">

    <ul id="menu">

      <li class="active">第一个按钮</li>

      <li>第二个按钮</li>

      <li>第三个按钮</li>

      <li>第四个按钮</li>

    </ul>

    <div id="pannel">

      <div class="active"></div>

      <div></div>

      <div></div>

      <div></div>

    </div>

  </div>

  

</body>

</html>

  回来再总结下思路吧:

  1:CSS布局要点:默认按钮和内容区域第一个为active状态,

  2:写jQuery时通过addClass()/removeClass()来改变卡片的状态;

转载于:https://www.cnblogs.com/tiny-jiao/p/6432227.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值