zoukankan      html  css  js  c++  java
  • 使用Swiperable tabs 切换效果-----(swiper tab 滑动切换)

    Github上的案例:

    效果图如下:

    代码如下:

    index.html

    <!DOCTYPE html>
    <html lang="en" >
    <head>
      <meta charset="UTF-8">
      <title>CodePen - Swipeable Tabs</title>
      <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
    <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/Swiper/3.1.2/css/swiper.min.css'><link rel="stylesheet" href="./style.css">
    
    </head>
    <body>
    <!-- partial:index.partial.html -->
    <div class="intro">
            <h1>Swipeable Tabs</h1>
            <p>[Android - Material Design]</br>made by <a href="https://github.com/nolimits4web/Swiper">swiperjs</p>
        </div>
        <div class="swiper-container">
            <!-- Add Pagination -->
            <div class="swiper-pagination">
            </div>
            <div class="swiper-wrapper">
                <div class="swiper-slide">Tab 1</div>
                <div class="swiper-slide">Tab 2</div>
                <div class="swiper-slide">Tab 3</div>
                <div class="swiper-slide">Tab 4</div>
            </div>
        </div>
    <!-- partial -->
      <script src='https://cdnjs.cloudflare.com/ajax/libs/Swiper/3.1.2/js/swiper.min.js'></script><script  src="./script.js"></script>
    
    </body>
    </html>

    CSS代码:

    :root {
      box-sizing: border-box;
      font-size: 62.5%;
    }
    
    *,
    *::before,
    *::after {
      box-sizing: inherit;
    }
    
    body {
      background-color: #745E73;
      color: #fff;
      margin: 0;
      -webkit-font-smoothing: antialiased;
    }
    
    a {
      text-decoration: none;
    }
    
    .intro {
      text-align: center;
    }
    .intro h1 {
      color: #EFEFEF;
      font-size: 3rem;
      margin: 60px 0 0;
      font-weight: bold;
      font-family: monospace;
    }
    @media screen and (min- 800px) {
      .intro h1 {
        font-size: 4rem;
      }
    }
    .intro p {
      color: #E0CF79;
      font-size: 1.3rem;
      line-height: 1.5;
    }
    .intro a {
      color: #40DFBB;
      font-weight: bold;
      text-decoration: none;
    }
    
    .swiper-container {
      width: 100%;
      height: 100%;
      margin: 50px auto 0;
    }
    @media screen and (min- 800px) {
      .swiper-container {
        width: 70%;
        margin-left: 15%;
      }
    }
    
    .swiper-slide {
      background: #fff;
      color: #333;
      font-size: 1.8rem;
      min-height: 300px;
      display: flex;
      justify-content: center;
      align-items: center;
      text-align: center;
    }
    
    .swiper-container-horizontal > .swiper-pagination {
      top: 0;
      bottom: auto;
    }
    .swiper-container-horizontal > .swiper-pagination .swiper-pagination-bullet {
      margin: 0;
    }
    
    .active-mark {
      background: #ffeb3b;
      width: 25%;
      height: 4px;
      position: absolute;
      left: 0;
      top: 52px;
      transition: left 0.2s ease-out;
    }
    
    .swiper-pagination-bullet {
      background-color: #00D42B;
      border-radius: 0;
      box-sizing: border-box;
      color: #0e8927;
      cursor: pointer;
      font-size: 1.6rem;
      font-weight: normal;
      opacity: 1;
      height: 56px;
      width: 25%;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      text-align: center;
      transition: font-weight 0.22s ease;
    }
    .swiper-pagination-bullet:nth-of-type(1).swiper-pagination-bullet-active ~ .active-mark {
      left: 0%;
    }
    .swiper-pagination-bullet:nth-of-type(2).swiper-pagination-bullet-active ~ .active-mark {
      left: 25%;
    }
    .swiper-pagination-bullet:nth-of-type(3).swiper-pagination-bullet-active ~ .active-mark {
      left: 50%;
    }
    .swiper-pagination-bullet:nth-of-type(4).swiper-pagination-bullet-active ~ .active-mark {
      left: 75%;
    }
    .swiper-pagination-bullet:first-of-type.swiper-pagination-bullet-active ~ .active-mark {
      left: 0;
    }
    
    .swiper-pagination-bullet-active {
      font-weight: bold;
    }

    Javscript代码:

    var swiper = new Swiper('.swiper-container', {
                pagination: '.swiper-pagination',
                slidesPerView: 1,
                paginationClickable: true,
                loop: true,
                   paginationBulletRender: function (index, className) {
                    var tabsName = ['Apps', 'Tricks', 'News', 'Games'];
                    if ( index === (tabsName.length - 1) ) {
                              return    '<span class="' + className + '">'
                                      + tabsName[index] + '</span>'
                                      + '<div class="active-mark "></div>';
                    }
                    return '<span class="' + className + '">' + tabsName[index] + '</span>';
                    }
            });
  • 相关阅读:
    VM439:1 https://unidemo.dcloud.net.cn 不在以下 request 合法域名列表中,请参考
    vue点击出现蒙版
    vue实现轮播图
    js函数调用的几种方法
    js中的object类型
    vue报错笔记
    vue中项目如何引入sass (vue-cli项目)
    vue编写轮播图组件
    VSCode配置 Debugger for Chrome插件
    就是一段程序,可以求出N个不等长列表中取N个元素形成的所有组合
  • 原文地址:https://www.cnblogs.com/hechunfeng/p/15478490.html
Copyright © 2011-2022 走看看