利用jquery eq()属性实现Tab标签的切换效果

利用jquery eq()属性实现Tab标签的切换效果

DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Tab标签的切换效果title>
  <style>
    .tab {
      margin: 200px;
    }

    .tab-bay {
      overflow: hidden;
      margin: 0;
      padding: 0;
    }

    ul li {
      list-style: none;
      float: left;
      /* margin: 0 20px; */
    }

    .tab-item {
      padding: 0 20px;
      height: 40px;
      box-sizing: border-box;
      display: flex;
      align-items: center;
      justify-content: center;
      list-style: none;
      font-size: 16px;
      font-weight: 500;
      color: #333333;
      position: relative;
      border: 1px solid #c3c9d3;
      cursor: pointer;
      margin-left: -1px;
    }

    .tab-item:hover {
      color: #409eff;
    }

    .active {
      background: #409eff;
      border-color: #409eff;
      color: #FFFFFF;
    }

    .active:hover {
      color: #FFFFFF;
    }

    .tab-item:first-child {
      border-top-left-radius: 4px;
      margin-left: 0;
    }

    .tab-item:last-child {
      border-top-right-radius: 4px;
    }

    .conter-son {
      background: rgb(255, 255, 255);
      border: 1px solid #c3c9d3;
      margin-top: -1px;
      height: 100px;
      line-height: 100px;
      border-radius: 4px;
      border-top-left-radius: 0px;
    }

    .conter-sona {
      display: none;
      text-align: center;
    }

    .conter-sonactive {
      display: block;
    }
  style>
head>

<body>
  <div class="tab">
    <ul class="tab-bay">
      <li class="tab-item active">tab1li>
      <li class="tab-item">tab2li>
      <li class="tab-item">tab3li>
      <li class="tab-item">tab4li>
    ul>
    <div class="conter-son">
      <div class="conter-sona conter-sonactive">
        <span>1span>
      div>
      <div class="conter-sona">
        <span>2span>
      div>
      <div class="conter-sona">
        <span>3span>
      div>
      <div class="conter-sona">
        <span>4span>
      div>
    div>
  div>

  <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.js">script>
  <script>
    $(function () {
      $('.tab-bay .tab-item').click(function () {
        $(this).addClass('active').siblings().removeClass('active');
        $('.conter-son .conter-sona').eq($(this).index()).show().siblings().hide();
      });
    });
  script>
body>

html>

你可能感兴趣的:(js,html,jquery,css,css3)