您好,登錄后才能下訂單哦!
這篇文章主要講解了“微信小程序怎么實現tab頁面切換效果”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“微信小程序怎么實現tab頁面切換效果”吧!
效果圖
html 頁面
<view class="bgwhite"> <scroll-view scroll-x="true"> <view class="width200 row nowrap"> <view class="f32 c666 p-tb-20 p-lr-30 {{currentData == 0 ? 'topic' : ''}}" data-current="0" bindtap='checkCurrent'>第1題</view> <view class="f32 c666 p-tb-20 p-lr-30 {{currentData == 1 ? 'topic' : ''}}" data-current="1" bindtap='checkCurrent'>第2題</view> <view class="f32 c666 p-tb-20 p-lr-30 {{currentData == 2 ? 'topic' : ''}}" data-current="2" bindtap='checkCurrent'>第3題</view> <view class="f32 c666 p-tb-20 p-lr-30 {{currentData == 3 ? 'topic' : ''}}" data-current="3" bindtap='checkCurrent'>第4題</view> <view class="f32 c666 p-tb-20 p-lr-30 {{currentData == 4 ? 'topic' : ''}}" data-current="4" bindtap='checkCurrent'>第5題</view> <view class="f32 c666 p-tb-20 p-lr-30 {{currentData == 5 ? 'topic' : ''}}" data-current="5" bindtap='checkCurrent'>第6題</view> </view> </scroll-view> </view> <swiper current="{{currentData}}" class='width200' duration="300" bindchange="bindchange"> <swiper-item> <view class="m-lr-20"> <view class="row p-t-30 p-b-10"> <view class="radio_singel f22 p-lr-10">單選</view> <view class="m-l-20 weight500 f28">題目1</view> </view> <radio-group bindchange="radioChange"> <label class="row alignitems bgwhite p-tb-25 p-lr-20 radius15 m-t-20"> <view class="weui-cell__hd"> <radio checked="true" color="#1989f9"/> </view> <view class="f30 weight500 m-l-10">A、1111</view> </label> <label class="row alignitems bgwhite p-tb-25 p-lr-20 radius15 m-t-20"> <view class="weui-cell__hd"> <radio color="#1989f9"/> </view> <view class="f30 weight500 m-l-10">B、2222</view> </label> <label class="row alignitems bgwhite p-tb-25 p-lr-20 radius15 m-t-20"> <view class="weui-cell__hd"> <radio color="#1989f9"/> </view> <view class="f30 weight500 m-l-10">C、3333</view> </label> <label class="row alignitems bgwhite p-tb-25 p-lr-20 radius15 m-t-20"> <view class="weui-cell__hd"> <radio color="#1989f9"/> </view> <view class="f30 weight500 m-l-10">D、4444</view> </label> </radio-group> </view> </swiper-item> <swiper-item> <view class="m-lr-20"> <view class="row p-t-30 p-b-10"> <view class="radio_singel f22 p-lr-10">單選</view> <view class="m-l-20 weight500 f28">題目2</view> </view> <video src="" ></video> <radio-group bindchange="radioChange"> <label class="row alignitems bgwhite p-tb-25 p-lr-20 radius15 m-t-20"> <view class="weui-cell__hd"> <radio checked="true" color="#1989f9"/> </view> <view class="f30 weight500 m-l-10">A、1111</view> </label> <label class="row alignitems bgwhite p-tb-25 p-lr-20 radius15 m-t-20"> <view class="weui-cell__hd"> <radio color="#1989f9"/> </view> <view class="f30 weight500 m-l-10">B、2222</view> </label> <label class="row alignitems bgwhite p-tb-25 p-lr-20 radius15 m-t-20"> <view class="weui-cell__hd"> <radio color="#1989f9"/> </view> <view class="f30 weight500 m-l-10">C、3333</view> </label> <label class="row alignitems bgwhite p-tb-25 p-lr-20 radius15 m-t-20"> <view class="weui-cell__hd"> <radio color="#1989f9"/> </view> <view class="f30 weight500 m-l-10">D、4444</view> </label> </radio-group> </view> </swiper-item> <swiper-item> </swiper-item> <swiper-item> </swiper-item> <swiper-item> </swiper-item> </swiper> <view class="footer p-tb-25"> <view class="m-lr-30 row just-btw"> <view class="row alignitems" bindtap="prevClick"> <image src="../../images/prev_icon.png" mode="aspectFit" ></image> <view class="f36 weight500 m-l-10">上一題</view> </view> <view class="jiaojuanbtn f30 white p-tb-20">交卷</view> <view class="row alignitems" bindtap="nextClick"> <view class="f36 weight500 m-r-10">下一題</view> <image src="../../images/next_icon.png" mode="aspectFit" ></image> </view> </view> </view>
css樣式
.topic{ position: relative; color:#000; } .topic::before{ position: absolute; content:""; width:80rpx; height:6rpx; background: #1989f9; border-radius: 20rpx; bottom: 0; left:50%; transform: translateX(-50%); } .radio_singel{ background: #e6f7ff; border:1px solid #91d4fe; color:#1890ff; } .footer{ position: fixed; bottom: 0; background-color: #fff; left:0; right:0; }
js 頁面
data: { currentData:0, }, //獲取當前滑塊的index bindchange(e){ const that = this; that.setData({ currentData: e.detail.current }) }, //點擊切換,滑塊index賦值 checkCurrent(e){ const that = this; if (that.data.currentData === e.target.dataset.current){ return false; }else{ that.setData({ currentData: e.target.dataset.current }) } }, //上一題 prevClick(){ var currentData = this.data.currentData - 1 if(currentData + 1 == 0){ wx.showToast({ title: '這是第1題了', }) }else{ this.setData({ currentData:currentData }) } }, //下一題 nextClick(){ this.setData({ currentData:this.data.currentData + 1 }) },
感謝各位的閱讀,以上就是“微信小程序怎么實現tab頁面切換效果”的內容了,經過本文的學習后,相信大家對微信小程序怎么實現tab頁面切換效果這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。