애플 릿 페이지 효과 구현

본 논문 의 사례 는 애플 릿 이 페이지 효 과 를 나타 내 는 구체 적 인 코드 를 공유 하여 여러분 께 참고 하 시기 바 랍 니 다.구체 적 인 내용 은 다음 과 같 습 니 다.

<view class="pages_box">
  <view bindtap="pagesFn" class="{{pagesNum==0?'active':''}}" data-type="0">   </view>
  <block wx:for="shujuDataArr11111" wx:key="index" wx:if="{{index+1<4}}">
    <view wx:if="{{tyindex+index <=maxPages}}" bindtap="pagesFn" class="{{pagesNum==tyindex+index?'active':''}}" data-type="{{tyindex+index}}">{{tyindex+index}}</view>
  </block>
  <view bindtap="pagesFn" class="{{pagesNum==-1?'active':''}}" data-type="-1">   </view>
</view>
js:

// pages/ceshiPages/index.js
Page({
 
  /**
   *        
   */
  data: {
    pagesNum:1,
    maxPages:15,//     
    tyindex:1
  },
 
  /**
   *       --      
   */
  onLoad: function (options) {
 
  },
    pagesFn:function(e){
    let type = e.currentTarget.dataset.type;
    let _that = this;
    if(typeof type == "string"){//   
      if(type == "previous_page"){//   
        if(_that.data.pagesNum-1 >0){
          _that.setData({
            pagesNum:_that.data.pagesNum-1,
            tyindex:_that.data.pagesNum-1,
          })
        }
        console.log(_that.data.pagesNum)
      }else{//   
        if(_that.data.pagesNum+1 <= _that.data.maxPages){
          if((_that.data.pagesNum+1)%3 == 0){
            _that.setData({
              tyindex:_that.data.pagesNum+1,
            })
          }
          _that.setData({
            pagesNum:_that.data.pagesNum+1,
          })
          console.log(_that.data.pagesNum)
        }
      }
    }else{
      console.log(_that.data.pagesNum)
      if(type>_that.data.pagesNum){
        if(type <= _that.data.maxPages){
          _that.setData({
            tyindex:type,
            pagesNum:type,
          })
        }
      }
      if(type<_that.data.pagesNum){
        if(type >=1){
          _that.setData({
            tyindex:type,
            pagesNum:type,
          })
        }
      }
      console.log(_that.data.pagesNum)
    }
  },
  /**
   *       --          
   */
  onReady: function () {
 
  },
 
  /**
   *       --      
   */
  onShow: function () {
 
  },
 
  /**
   *       --      
   */
  onHide: function () {
 
  },
 
  /**
   *       --      
   */
  onUnload: function () {
 
  },
 
  /**
   *           --        
   */
  onPullDownRefresh: function () {
 
  },
 
  /**
   *              
   */
  onReachBottom: function () {
 
  },
 
  /**
   *          
   */
  onShareAppMessage: function () {
 
  }
})
CSS:

/* pages/ceshiPages/index.wxss */
.pages_box{
  margin-top: 20rpx;
  display: flex;
  display: -webkit-flex;
  flex-direction: row;
  justify-content: space-around;
  align-content: flex-start;
  flex-wrap: nowrap;
}
.pages_box>view{
  line-height: 60rpx;
  font-size: 30rpx;
  border: 1px solid #A0A0A0;
  background-color: #F7F7F7;
  display: inline-block;
  padding: 0 25rpx;
  margin-left: 12rpx;
  color: #64646C;
  border-radius: 10rpx;
}
.pages_box>view.active{
  background-color: #FCD821;
  border-color: #F39800;
}
.pages_box>view:last-child,.pages_box>view:first-child{
  border-radius: 60rpx;
  padding: 0 30rpx;
}
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기