微信小程序實現側邊導航欄
本文實例為大傢分享瞭微信小程序實現側邊導航欄的具體代碼,供大傢參考,具體內容如下
效果圖
wxml
<view class='productNav'> <!-- 左側 --> <view class='left'> <view class="{{active==0?'selected':'normal'}}" id="0" bindtap='switchNav'>為您推薦</view> <view class="{{active==1?'selected':'normal'}}" id="1" bindtap='switchNav'>電腦</view> <view class="{{active==2?'selected':'normal'}}" id="2" bindtap='switchNav'>手機</view> </view> <!-- 右側 --> <view class='right'> <view class='type'> <!-- current:當前所在滑塊的 index --> <!-- vertical:滑動方向是否為縱向 --> <swiper current='{{currentTab}}' vertical='{{true}}'> <!-- catchtouchmove 阻止彈窗後滾動穿透 --> <swiper-item id="0" catchtouchmove="false"> 為您推薦 </swiper-item> <swiper-item id="1" catchtouchmove="false"> 手機 </swiper-item> <swiper-item id="2" catchtouchmove="false"> 電腦 </swiper-item> </swiper> </view> </view> </view>
js
Page({ data: { active:0, currentTab:0 }, switchNav: function (e) { var page = this; var id = e.target.id; if (this.data.currentTab == id) { return false; } else { page.setData({ currentTab: id }); } page.setData({ active: id }); } })
wxss
.productNav{ display: flex; flex-direction: row; font-family: "Microsoft YaHei" } .left{ width: 25%; font-size: 30rpx; background-color: #f4f4f4; } .left view{ text-align: center; height: 90rpx; line-height: 90rpx; } .selected{ background-color: #fff; border-left: 2px solid #E54847; font-weight: bold; color: #E54847; } .normal{ background-color: #f4f4f4; border-bottom: 1px solid #f2f2f2; } .right{ width:75%; margin: 0; } swiper{ height: 500px; }
以上就是本文的全部內容,希望對大傢的學習有所幫助,也希望大傢多多支持WalkonNet。