移动端 tab 页切换

移动端 tab 页切换

html

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

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="index.css">
  <script src="./jquery.min.js" type="text/javascript" charset="utf-8"></script>
  <title>tab切换</title>

</head>

<body>
  <div class="tab_box">
    <ul id="ul_box">
      <li class="tab_active" data-index="1">
        <span id="tab_1">检测数据</span>
      </li>
      <li class="no-underline" data-index="2">
        <span id="tab_2">通用物质</span>
      </li>
      <li class="no-underline" data-index="3">
        <span id="tab_3">试剂剩余量</span>
      </li>
      <li class="no-underline" data-index="4">
        <span id="tab_4">质控品</span>
      </li>
      <li class="no-underline" data-index="5">
        <span id="tab_5">质控数据</span>
      </li>
      <li class="no-underline" data-index="6">
        <span id="tab_6">质控图</span>
      </li>
      <li class="no-underline" data-index="7">
        <span id="tab_7">定标曲线</span>
      </li>
      <li class="no-underline" data-index="8">
        <span id="tab_8">异常信息</span>
      </li>
    </ul>
  </div>
  <div class="content_tab">
    <div id="con_tab1" class="con_active">检测数据</div>
    <div id="con_tab2" class="con_no_active">通用物质</div>
    <div id="con_tab3" class="con_no_active">实际剩余量</div>
    <div id="con_tab4" class="con_no_active">质控品</div>
    <div id="con_tab5" class="con_no_active">质控数据</div>
    <div id="con_tab6" class="con_no_active">质控图</div>
    <div id="con_tab7" class="con_no_active">定标曲线</div>
    <div id="con_tab8" class="con_no_active">异常信息</div>
  </div>
</body>
<script>
  $('li').click(function () {
    $(this).removeClass("no-underline").addClass("tab_active").siblings().addClass("no-underline").removeClass("tab_active")
    var index = Number($(this).attr('data-index'))
    $('#con_tab' + index).addClass("con_active").removeClass("con_no_active").siblings().addClass("con_no_active")
  })
</script>

</html>

css

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    text-decoration: none;
    list-style: none;
}
a {
    background-color: transparent;
    -webkit-text-decoration-skip: objects;
}
a,
div,
header,
span {
    -webkit-tap-highlight-color: rgba(255, 255, 255, 0);
}
.tab_box {
    position: relative;
    height: 49px
}
.tab_box ul {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 49px;
    background-color: #fff;
}
.tab_box ul {
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
}
.tab_box ul::-webkit-scrollbar {
    display: none;
    width: 0
}
.tab_box ul li {
    display: inline-block;
    width: 90px;
    height: 100%;
    overflow: hidden
}
.tab_box ul li span {
    font-size: 15px;
    padding: 0 3px;
    width: 100%;
    text-align: center;
    color: #000000;
    font-size: 14px;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden
}

.tab_box ul .tab_active {
    border-bottom: 2px solid #000000;
    background-color: #f2f2f2;
}

.tab_box ul .tab_active span {
    font-weight: 700;
}

.tab_box ul .tab_active.no-underline {
    font-weight: 400;
    border-bottom: 0;
}

.content_tab {
    width: 100%;
    height: 900px;
}
.con_active{
    display: block;
}
.con_no_active{
    display: none;
}
#con_tab1{
    width: 100%;
    height: 100%;
    background-color: pink;
}
#con_tab2{
    width: 100%;
    height: 100%;
    background-color: red;
}
#con_tab3{
    width: 100%;
    height: 100%;
    background-color: green;
}
#con_tab4{
    width: 100%;
    height: 100%;
    background-color: yellow;
}
#con_tab5{
    width: 100%;
    height: 100%;
    background-color: orange;
}
#con_tab6{
    width: 100%;
    height: 100%;
    background-color: yellowgreen;
}
#con_tab7{
    width: 100%;
    height: 100%;
    background-color: blue;
}
#con_tab8{
    width: 100%;
    height: 100%;
    background-color: blueviolet;
}
[removed] $(function() { function setCurrentSlide(ele, index) { $(".swiper1 .swiper-slide").removeClass("selected"); ele.addClass("selected"); //swiper1.initialSlide=index; } var swiper1 = new Swiper('.swiper1', { // 设置slider容器能够同时显示的slides数量(carousel模式)。 // 可以设置为number或者 'auto'则自动根据slides的宽度来设定数量。 // loop模式下如果设置为'auto'还需要设置另外一个参数loopedSlides。 slidesPerView: 5.5, paginationClickable: true,//此参数设置为true时,点击分器的指示点分器会控制Swiper切换。 spaceBetween: 10,//slide之间的距离(单位px)。 freeMode: true,//默认为false,普通模式:slide滑动时只滑动一格,并自动贴合wrapper,设置为true则变为free模式,slide会根据惯性滑动且不会贴合。 loop: false,//是否可循环 onTab: function(swiper) { var n = swiper1.clickedIndex; } }); swiper1.slides.each(function(index, val) { var ele = $(this); ele.on("click", function() { setCurrentSlide(ele, index); swiper2.slideTo(index, 500, false); //mySwiper.initialSlide=index; }); }); var swiper2 = new Swiper('.swiper2', { //freeModeSticky 设置为true 滑动会自动贴合 direction: 'horizontal',//Slides的滑动方向,可设置水平(horizontal)或垂直(vertical)。 loop: false, // effect : 'fade',//淡入 //effect : 'cube',//方块 //effect : 'coverflow',//3D流 // effect : 'flip',//3D翻转 autoHeight: true,//自动高度。设置为true时,wrapper和container会随着当前slide的高度而发生变化。 onSlideChangeEnd: function(swiper) { //回调函数,swiper从一个slide过渡到另一个slide结束时执行。 var n = swiper.activeIndex; setCurrentSlide($(".swiper1 .swiper-slide").eq(n), n); swiper1.slideTo(n, 500, false); } }); }); [removed]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值