zoukankan      html  css  js  c++  java
  • 小程序选项卡小Demo,可滑动控制

    思绪
    1.选项卡使用scroll-view,实现可以滑动控制效果;
    2.使用current控制选项卡标题和内容的统一,实现同步操作;
    3.winHeight 这个是我最常用的var calc = clientHeight * rpxR - 440; 440这个值是你所不需要计算的高度值,取决于你除内容之外的高度;
    wxml文件

    <view class="pinConDet">
      <view class='title'>标题</view>
      <view class='con'>
        <scroll-view scroll-x="true" class="tab-h" scroll-left="{{scrollLeft}}" class='tabBox'>
            <view class="tab-item {{currentTab==0?'active':''}}"  data-current="0" bindtap="swichNav">选项1</view>
            <view class="tab-item {{currentTab==1?'active':''}}" data-current="1" bindtap="swichNav">选项2</view>    
        </scroll-view>
        <swiper class="tab-content" current="{{currentTab}}" duration="300" bindchange="switchTab"
         style="height:{{winHeight}}rpx">
          <swiper-item>
            <scroll-view scroll-y="true" class="scoll-h" >
              <view class="title1">
                选项卡1内容
              </view>
            </scroll-view>
          </swiper-item>
          <swiper-item>
            <scroll-view scroll-y="true" class="scoll-h" >
              <view class="title1">
                选项卡2内容
              </view>
            </scroll-view>
          </swiper-item>
        </swiper>
      </view>
    </view>

    wxss文件

    .pinConDet{
      padding: 30rpx;
    }
    .pinConDet .title{
      color: #3491f0;
      font-size: 15px;
      height: 100rpx;
      line-height: 100rpx;
    }
    .pinConDet .tabBox{
      border-bottom: 1px solid #3491f0;
    }
    .pinConDet .tab-item{
      font-size: 15px;
      display:inline-block;
      width: 120rpx;
      margin-left: 20rpx;
      background: #e9f2fa;
      color: #3491f0;
      height: 60rpx;
      line-height: 60rpx;
      text-align: center;
    }
    .pinConDet .active{
      background: #3491f0;
      color: #fff;
    }
    .tab-content swiper-item view{
      padding: 30rpx;
      font-size: 15px;
    }

    js文件

    var app = getApp()
    Page({
      data: {
        winHeight: "",//窗口高度
        currentTab: 0, //预设当前项的值
        scrollLeft: 0, //tab标题的滚动条位置
        showView: false,
        cWayshow: false,
      },
      // 滚动切换标签样式
      switchTab: function (e) {
        this.setData({
          currentTab: e.detail.current
          //获取当前事件current的值;
        });
        this.checkCor();
      },
      // 点击标题切换当前页时改变样式
      swichNav: function (e) {
        var cur = e.target.dataset.current;
        if (this.data.currentTaB == cur) { return false; }
        else {
          this.setData({
            currentTab: cur
          })
        }
      },
      //判断当前滚动超过一屏时,设置tab标题滚动条。
      checkCor: function () {
        if (this.data.currentTab > 4) {
          this.setData({
            scrollLeft: 300
          })
        } else {
          this.setData({
            scrollLeft: 0
          })
        }
      },
      onLoad: function (options) {
        showView: (options.showView == "true" ? true : false);
        cWayshow: (options.showView == "true" ? true : false);
        var that = this;
        //  高度自适应
        wx.getSystemInfo({
          success: function (res) {
            var clientHeight = res.windowHeight,
              clientWidth = res.windowWidth,
              rpxR = 750 / clientWidth;
            console.log(clientHeight)
            var calc = clientHeight * rpxR - 440;
            console.log(calc)
            that.setData({
              winHeight: calc
            });
          }
        });
      }
    })

    最后实现效果样式呈现

  • 相关阅读:
    iOS添加Google语言识别功能
    转载:Ajax中get与post请求详解
    SSH:Spring+Spring MVC+hibernate整合开发笔记
    IDEA中创建maven web项目的详细部署步骤
    C++实现RTMP协议发送H.264编码及AAC编码的音视频
    C++ 勘误
    Postgresql ODBC驱动,用sqlserver添加dblink跨库访问postgresql数据库
    .Net NPOI 上传excel文件、提交后台获取excel里的数据
    .Net NPOI 根据excel模板导出excel、直接生成excel
    .Net 登陆的时候添加验证码
  • 原文地址:https://www.cnblogs.com/jiayeyuan/p/8393021.html
Copyright © 2011-2022 走看看