• swiper 套swiper 父横向,子横向或者竖向


    html

    <view class="nav-top">
       <view  class="nav-top-div1 {{currentView==0?'active':''}}" data-typeCurrent='0' bindtap="bindtap">视频</view>
       <view  class="nav-top-div2 {{currentView==1?'active':''}}" data-typeCurrent='1' bindtap="bindtap">推荐</view>
       <view  class="nav-top-div3 {{currentView==2?'active':''}}" data-typeCurrent='2' bindtap="bindtap">直播</view>
    </view>
    <swiper class="swipercont" bindchange='bindchange2' current="{{currentView}}">
    <block>
      <swiper-item>
        <swiper class="swiper2" vertical="true" >
          <block wx:for="{{background1}}" wx:key="*this">
            <swiper-item>
              <view class="swiper-item {{item}}">{{item}}</view>
            </swiper-item>
          </block>
        </swiper>
      </swiper-item>
      <swiper-item>
        <swiper class="swiper2" bindchange='bindchange' bindtransition='bindtransition' bindanimationfinish='bindanimationfinish' current="{{page2current}}">
          <block wx:for="{{background}}" wx:key="*this">
            <swiper-item>
              <view class="swiper-item {{item}}">{{item}}</view>
            </swiper-item>
          </block>
        </swiper>
      </swiper-item>
      <swiper-item>
        <scroll-view  scroll-y="true" style="height:100%" >
          <view id="demo1" class="scroll-view-item demo-text-1">2</view>
          <view id="demo2"  class="scroll-view-item demo-text-2">3</view>
          <view id="demo3" class="scroll-view-item demo-text-3">4</view>
        </scroll-view>
      </swiper-item>
    </block>
    </swiper>
    

      JS 

    Page({
     
      /**
       * 页面的初始数据
       */
      data: {
        currentView:0,//默认显示第一个第div
        background1: ['视频模块div1', '视频模块div2', '视频模块div3'],
        background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
        page2current:0,//默认swiperitem
        isTotouch:0,
      },
     
      /**
       * 生命周期函数--监听页面加载
       */
      onLoad: function (options) {
      },
      bindchange2(e){
        console.log('父亲swiper')
        const {current, source}=e.detail;
        this.setData({
          currentView:current
        })
      },
      bindchange(e){
        console.log('子swiper')
        const {current, source}=e.detail;
        this.setData({
          page2current:current
        });
    
      },
      bindanimationfinish(e){
        console.log('子swiperfinish')
        if(this.data.page2current==2){
          if(this.data.isTotouch==4){
            this.setData({
              currentView:2,
            })
          }else{
            this.setData({
              isTotouch:4
            })
          }
        }else if(this.data.page2current==0){
            if(this.data.isTotouch==-1){
              this.setData({
                currentView:0,
              })
            }else{
              this.setData({
                isTotouch:-1
              })
            }
        }
      },
      bindtap(event){
        console.log(event);
        const type=Number(event.currentTarget.dataset.typecurrent);
        let page2current=0;
        if(type==2){
          page2current=2
        }else if(type==0){
          page2current=0
        }
        this.setData({
          currentView:type,
          page2current:page2current
        })
      },
     
      /**
       * 生命周期函数--监听页面初次渲染完成
       */
      onReady: function () {
     
      },
     
      /**
       * 生命周期函数--监听页面显示
       */
      onShow: function () {
     
      },
     
      /**
       * 生命周期函数--监听页面隐藏
       */
      onHide: function () {
     
      },
     
      /**
       * 生命周期函数--监听页面卸载
       */
      onUnload: function () {
     
      },
     
      /**
       * 页面相关事件处理函数--监听用户下拉动作
       */
      onPullDownRefresh: function () {
     
      },
     
      /**
       * 页面上拉触底事件的处理函数
       */
      onReachBottom: function () {
     
      },
     
      /**
       * 用户点击右上角分享
       */
      onShareAppMessage: function () {
     
      }
    })
    

      CSS

    .mian{
      position: absolute;
      height: 100%;
      left:0;
      top:0;
       2260rpx;
    }
    .mian-div1{
       100vw;
      height: 100vh;
      background-color: #00ff00;
      float: left;
    }
    .mian-div2{
       100vw;
      height: 100vh;
      background-color: #00ff00;
      float: left;
    }
    .mian-div3{
       100vw;
      height: 100vh;
      background-color: #00ff00;
      float: left;
    }
    .swiper2{
       100%;
      height: 100%;
    }
    .nav-top{
      position: absolute;
      top:20px;
      display: flex;
       500rpx;
      left:0;
      z-index: 1;
    }
    .nav-top-div1,.nav-top-div2,.nav-top-div3{
      flex:1;
      font-size: 30rpx;
      text-align: center;
      color:#000;
    }
    .nav-top-div1.active{
      color:#ff0000;
    }
    .nav-top-div2.active{
      color:#ff0000;
    }
    .nav-top-div3.active{
      color:#ff0000;
    }
    .swiper-item{
      text-align: center;
       100%;
      padding-top:300rpx;
      font-size: 40rpx;
    }
    .scroll-view-item{
      height: 600rpx;
    }
    .cont{
       100vw;
      height: 100vh;
      position: relative;
      overflow: hidden;
    }
    .swipercont{
       100vw;
      height: 100vh;
      background-color: #f0f;
    }
    

      

    记下点滴,等老了慢慢欣赏
  • 相关阅读:
    机器学习系列-tensorflow-01-急切执行API
    Python3基础-代码阅读系列—优惠码生成
    英语口语练习系列-C01-好棒
    Python3基础系列——枚举类型大揭秘
    Python3字符串-最容易理解的方式
    英语词性系列-B02-动词
    专业方向系列-02-基于深度学习的诊断方法
    英语词性系列-B01-名词
    英语进阶系列-A06-本周总结
    Python数据可视化系列-02-pyecharts可视化非常cool
  • 原文地址:https://www.cnblogs.com/binmengxue/p/15290068.html
Copyright © 2020-2023  润新知