1. 程式人生 > >微信小程序之swiper

微信小程序之swiper

wid src bin left sys ace solid col -c

swiper主要是輪播圖,在微信小程序中我用的如下模式:

技術分享圖片

index.wxml:

<view class="swiper-tab">
  <view class="swiper-tab-list {{currentTab==0 ? ‘on‘ : ‘‘}}" data-current="0" bindtap="swichNav" data-post-id=0>推薦</view>
  <view class="swiper-tab-list {{currentTab==1 ? ‘on‘ : ‘‘}}" data-current="1" bindtap="
swichNav" data-post-id=1>視頻</view> <view class="swiper-tab-list {{currentTab==2 ? ‘on‘ : ‘‘}}" data-current="2" bindtap="swichNav" data-post-id=2>本地</view> </view> <swiper current="{{currentTab}}" class="swiper-box" duration="1000rpx" style="height:{{winHeight -0}}px
" bindchange="bindChange"> <swiper-item> </swiper-item> <swiper-item> <view class="wrap">視頻</view> </swiper-item> <swiper-item> <view class="wrap">本地</view> </swiper-item> </swiper>

index.wxss:

.swiper-tab {
  display: flex;
  position:fixed;
  top:0;
  left:0;
  z-index:100;
  background: #fff;
  height:80rpx;
  width:800rpx;
  justify-content: space-between;
  border-bottom: 2rpx solid gainsboro;
  text-align: center;
  line-height:80rpx;
}

.swiper-tab-list {
  font-size: 30rpx;
  display: inline-block;
  width: 25%;
  color: #777;
}
.on {
  color: #7cba23;
  font-size:40rpx;
  border-bottom: 5rpx solid #7cba23;
}
.swiper-box{
 height: 100%;
 width: 100%;
 
}
.swiper-box{
  width:100%;
  margin-top:80rpx;
  font-size:32rpx;
 
}

index.js:

var app=getApp()
Page({
  data: {
    currentTab: 0,
    winWidth: 0,
    winHeight: 0,
  },
  onLoad:function(option){
    var that = this;
    wx:wx.getSystemInfo({
      success: function(res) {
        that.setData({
          winWidth:res.windowWidth,
          winHeight:res.windowHeight
        })
      }
    })
  },
  //點擊切換
  swichNav: function (e) {
    var that=this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
  },
  //滑動切換tab
  bindChange: function (e) {
    var that = this;
    that.setData({ currentTab: e.detail.current });
  }
})

更多效果連接:https://blog.csdn.net/qq273681448/article/details/71078017

希望對剛開始的你有所幫助!!

微信小程序之swiper