• <fieldset id="8imwq"><menu id="8imwq"></menu></fieldset>
  • <bdo id="8imwq"><input id="8imwq"></input></bdo>
    最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
    問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
    當前位置: 首頁 - 科技 - 知識百科 - 正文

    微信小程序滾動Tab實現左右可滑動切換

    來源:懂視網 責編:小采 時間:2020-11-27 22:32:26
    文檔

    微信小程序滾動Tab實現左右可滑動切換

    微信小程序滾動Tab實現左右可滑動切換: 微信小程序滾動Tab實現左右可滑動切換 效果: 最終效果如上。問題: 1、tab標題總共8個,所以一屏無法全部顯示。 2、tab內容區左右滑動切換時,tab標題隨即做標記(active)。 3、當active的標題不在當前屏顯示時,要使其能顯示到當前屏中。 一、w
    推薦度:
    導讀微信小程序滾動Tab實現左右可滑動切換: 微信小程序滾動Tab實現左右可滑動切換 效果: 最終效果如上。問題: 1、tab標題總共8個,所以一屏無法全部顯示。 2、tab內容區左右滑動切換時,tab標題隨即做標記(active)。 3、當active的標題不在當前屏顯示時,要使其能顯示到當前屏中。 一、w

     微信小程序滾動Tab實現左右可滑動切換

    效果:

    最終效果如上。問題:

    1、tab標題總共8個,所以一屏無法全部顯示。
    2、tab內容區左右滑動切換時,tab標題隨即做標記(active)。
    3、當active的標題不在當前屏顯示時,要使其能顯示到當前屏中。

    一、wxml結構

    tab標題因一排八個,所以使用 scroll-view組件,使其可橫向滾動。

    tab內容可左右滑動切換,使用swiper組件實現

    為了偷懶,所以數據都通過wx:for遍歷重復出來。

    說明:

    1、設置data-current屬性用于:點擊當前項時,通過點擊事件swichNav中處理e.dataset.current取到點擊的目標值。
    2、swiper組件的current組件用于控制當前顯示哪一頁
    3、swiper組件綁定change事件switchTab,通過e.detail.current拿到當前頁

    <view >
     <scroll-view scroll-x="true" class="tab-h" scroll-left="{{scrollLeft}}">
     <view class="tab-item {{currentTab==0?'active':''}}" data-current="0" bindtap="swichNav">健康</view>
     <view class="tab-item {{currentTab==1?'active':''}}" data-current="1" bindtap="swichNav">情感</view>
     <view class="tab-item {{currentTab==2?'active':''}}" data-current="2" bindtap="swichNav">職場</view>
     <view class="tab-item {{currentTab==3?'active':''}}" data-current="3" bindtap="swichNav">育兒</view>
     <view class="tab-item {{currentTab==4?'active':''}}" data-current="4" bindtap="swichNav">糾紛</view>
     <view class="tab-item {{currentTab==5?'active':''}}" data-current="5" bindtap="swichNav">青蔥</view>
     <view class="tab-item {{currentTab==6?'active':''}}" data-current="6" bindtap="swichNav">全部</view>
     <view class="tab-item {{currentTab==7?'active':''}}" data-current="7" bindtap="swichNav">其他</view>
     </scroll-view>
     <swiper class="tab-content" current="{{currentTab}}" duration="300" bindchange="switchTab"
     style="height:{{winHeight}}rpx">
     <swiper-item wx:for="{{[0,1,2,3,4,5,6,7]}}">
     <scroll-view scroll-y="true" class="scoll-h" >
     <block wx:for="{{[1,2,3,4,5,6,7,8]}}" wx:key="*this">
     <view class="item-ans">
     <view class="avatar">
     <image class="img" src="http://ookzqad11.bkt.clouddn.com/avatar.png"></image>
     </view>
     <view class="expertInfo">
     <view class="name">歡顏</view>
     <view class="tag">知名情感博主</view>
     <view class="answerHistory">134個回答,2234人聽過 </view>
     </view>
     <navigator url="/pages/askExpert/expertDetail" class="askBtn">問TA</navigator> 
     </view>
     </block>
     </scroll-view>
     </swiper-item>
     </swiper>
    </view>
    

    二、js部分

    微信小程序在開發起來,個人感覺挺像vue的,以數據驅動視圖的更新。所以在小程序中,不能直接操作dom,當然也不能使用jquery之類的庫。

    var app = getApp();
    Page({
     data:{
     winHeight:"",//窗口高度
     currentTab:0, //預設當前項的值
     scrollLeft:0, //tab標題的滾動條位置
     expertList:[{ //假數據
     img:"avatar.png",
     name:"歡顔",
     tag:"知名情感博主",
     answer:134,
     listen:2234
     }]
     },
     // 滾動切換標簽樣式
     switchTab:function(e){
     this.setData({
     currentTab:e.detail.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() { 
     var that = this; 
     // 高度自適應
     wx.getSystemInfo( { 
     success: function( res ) { 
     var clientHeight=res.windowHeight,
     clientWidth=res.windowWidth,
     rpxR=750/clientWidth;
     var calc=clientHeight*rpxR-180;
     console.log(calc)
     that.setData( { 
     winHeight: calc 
     }); 
     } 
     });
     }, 
     footerTap:app.footerTap
    })
    

    三、wxss樣式

    .tab-h{
     height: 80rpx;width: 100%; box-sizing: border-box;overflow: hidden;line-height: 80rpx;background: #F7F7F7; font-size: 16px; white-space: nowrap;position: fixed;top: 0; left: 0; z-index: 99;}
    .tab-item{margin:0 36rpx;display: inline-block;}
    .tab-item.active{color: #4675F9;position: relative;}
    .tab-item.active:after{ content: "";display: block;height: 8rpx;width: 52rpx;background: #4675F9;position: absolute; bottom: 0;left: 5rpx;border-radius: 16rpx;}
    .item-ans{ width: 100%;display: flex; flex-grow: row no-wrap;justify-content: space-between; padding: 30rpx;box-sizing: border-box; height: 180rpx;align-items: center;border-bottom: 1px solid #F2F2F2;}
    .avatar{width: 100rpx;height: 100rpx;position: relative;padding-right: 30rpx;}
    .avatar .img{width: 100%;height: 100%;}
    .avatar .doyen{width: 40rpx;height: 40rpx;position: absolute;bottom: -2px;right: 20rpx;}
    .expertInfo{font-size: 12px;flex-grow: 2;color: #B0B0B0;line-height: 1.5em;}
    .expertInfo .name{font-size: 16px;color:#000;margin-bottom: 6px;}
    .askBtn{ width: 120rpx;height: 60rpx;line-height: 60rpx;text-align: center;font-size: 14px; border-radius: 60rpx;border: 1px solid #4675F9; color:#4675F9;}
    .tab-content{margin-top: 80rpx;}
    .scoll-h{height: 100%;}
    
    

     如有疑問請留言或者到本站社區交流討論,感謝閱讀,希望能幫助大家,謝謝大家對本站的支持!

    聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

    文檔

    微信小程序滾動Tab實現左右可滑動切換

    微信小程序滾動Tab實現左右可滑動切換: 微信小程序滾動Tab實現左右可滑動切換 效果: 最終效果如上。問題: 1、tab標題總共8個,所以一屏無法全部顯示。 2、tab內容區左右滑動切換時,tab標題隨即做標記(active)。 3、當active的標題不在當前屏顯示時,要使其能顯示到當前屏中。 一、w
    推薦度:
    標簽: 小程序 滾動 滑動
    • 熱門焦點

    最新推薦

    猜你喜歡

    熱門推薦

    專題
    Top
    主站蜘蛛池模板: 国产精品国产三级国产AV主播| 欧美精品国产精品| 国产成人亚洲合集青青草原精品| 久久精品国产72国产精福利| 国产99re在线观看只有精品 | 久久精品嫩草影院| 久久国产免费观看精品3| 久久久精品波多野结衣| 日韩精品在线免费观看| 欧美精品一区二区久久| 国产精品无码无片在线观看| 伊人久久精品无码av一区| 久久97久久97精品免视看| 99国产精品私拍pans大尺度| 狠狠色丁香婷婷综合精品视频| 国产精品女同一区二区| 精品综合久久久久久888蜜芽| 亚洲精品美女久久777777| 无码国内精品久久人妻麻豆按摩| 国产午夜精品久久久久九九电影 | 日韩精品成人一区二区三区| 国产精品一级片| 成人午夜视频精品一区| 国产午夜精品无码| 国产精品视频永久免费播放| 精品福利视频一区二区三区| 国产伦精品免编号公布| 久久精品国产亚洲av麻豆小说| 久久综合精品国产二区无码| 欧美精品VIDEOSSEX少妇| 无码精品A∨在线观看| 久久久久女人精品毛片| 精品无码久久久久国产| 国产精品色内内在线播放| 国产精品第12页| 精品一区二区三区中文字幕| 一区二区三区国产精品| 国产成人精品在线观看| 国产久爱免费精品视频| 久久久久99精品成人片| 亚洲电影日韩精品|