微信小程序?qū)崿F(xiàn)側(cè)邊分類欄
更新時間:2019年10月21日 12:19:04 作者:吳小傻0
這篇文章主要為大家詳細介紹了微信小程序?qū)崿F(xiàn)側(cè)邊分類欄,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了微信小程序?qū)崿F(xiàn)側(cè)邊分類欄的具體代碼,供大家參考,具體內(nèi)容如下
效果圖
布局分析
分成三個盒子:
主盒子,左盒子,右盒子
–wxml–
<!--主盒子--> <view class="container"> <!-- 左側(cè)欄 --> <view class='nav_left'> <view class="nav_left_items {{curNav == 1 ? 'active' : ''}}" bindtap="switchRightTab" data-id="1"> 水果 </view> <view class="nav_left_items {{curNav == 2 ? 'active' : ''}}" bindtap="switchRightTab" data-id="2"> 干果 </view> <view class="nav_left_items {{curNav == 3 ? 'active' : ''}}" bindtap="switchRightTab" data-id="3"> 蔬菜 </view> <view class="nav_left_items {{curNav == 4 ? 'active' : ''}}" bindtap="switchRightTab" data-id="4"> 海鮮 </view> </view> <!-- 右側(cè)欄 --> <view class="nav_right"> <view wx:if="{{curNav==1}}"> <view class="nav_right_items"> <image src="../images/mihoutao.png"></image> <text>獼猴桃</text> </view> <view class="nav_right_items"> <image src="../images/longyan.png"></image> <text>龍眼</text> </view> <view class="nav_right_items"> <image src="../images/juzi.png"></image> <text>橘子</text> </view> <view class="nav_right_items"> <image src="../images/huolongguo.png"></image> <text>火龍果</text> </view> <view class="nav_right_items"> <image src="../images/caomei.png"></image> <text>草莓</text> </view> </view> <view wx:if="{{curNav==2}}"> <view class="nav_right_items"> <image src="../images/xiaweiyi.png"></image> <text>夏威夷果</text> </view> <view class="nav_right_items"> <image src="../images/kaixin.png"></image> <text>開心果</text> </view> <view class="nav_right_items"> <image src="../images/bigen.png"></image> <text>碧根果</text> </view> <view class="nav_right_items"> <image src="../images/mangguo.png"></image> <text>芒果</text> </view> </view> <view wx:if="{{curNav==3}}"> <view class="nav_right_items"> <image src="../images/huaye.png"></image> <text>花椰菜</text> </view> <view class="nav_right_items"> <image src="../images/shengcai.png"></image> <text>生菜</text> </view> <view class="nav_right_items"> <image src="../images/fanqie.png"></image> <text>番茄</text> </view> </view> </view> </view>
–js–
// pages/stock/stock_main.js Page({ /* 頁面的初始數(shù)據(jù) */ data: { curNav:1 }, /* 把點擊到的某一項 設為當前curNav */ switchRightTab:function(e){ let id = e.target.dataset.id; console.log(id); this.setData({ curNav: id }) } })
–wxss–
/* 1. 設置整個頁面的背景顏色 */ page{ background: #f5f5f5; /* 避免左側(cè)Item不夠時 被白色覆蓋*/ } /* 2.主盒子 */ .container { width: 100%; /* 寬度占屏幕的100% */ height: 100%; /* 高度占屏幕的100% */ background-color: #fff; /* 背景顏色 */ } /* 3.左盒子*/ /* 3.1. 左側(cè)欄主盒子總體設置 */ .nav_left{ position:absolute; /* 使用絕對定位 */ top:0px; /* 距離上邊距:0px */ left:0px; /* 距離左邊距:0px */ width: 25%; /* 每個item所占的寬度 */ background: #f5f5f5; /* 主盒子設置背景色為灰色 */ text-align: center; /* 文字居中顯示 */ } /* 3.2. 左側(cè)欄的每個item */ .nav_left .nav_left_items{ height: 40px; /* 每個item高40px*/ padding: 6px 0; /* 上內(nèi)邊距和下內(nèi)邊距是 6px[增加高度] 右內(nèi)邊距和左內(nèi)邊距是 0px*/ border-bottom: 1px solid #dedede; /* 設置下邊線 */ font-size: 14px; /* 設置文字大小:14px */ } /* 3.3. 左側(cè)欄list的item被選中時*/ .nav_left .nav_left_items.active{ background: #fff; /* 背景色變成白色 */ color: #3385ff; /* 字體編程藍色 */ border-left: 3px solid #3385ff; /* 設置邊框的寬度以及顏色 */ } /* 4.右盒子 */ /* 4.1. 右側(cè)欄主盒子總體設置 */ .nav_right{ position: absolute; /* 使用絕對定位 */ top: 0; /* 距離上邊距:0px */ left: 80px; /* 距離左邊距:80px */ width: 75%; /* 右側(cè)主盒子所占寬度 */ height: 600px; /* 右側(cè)主盒子所占高度 */ padding: 10px; /* 所有 4 個內(nèi)邊距都是 10px*/ box-sizing: border-box; /* 為元素指定的任何內(nèi)邊距和邊框都將在已設定的寬度和高度內(nèi)進行繪制*/ background: #fff; /* 右側(cè)主盒子背景顏色 */ } /* 4.2. 右側(cè)欄中的每個item */ .nav_right .nav_right_items{ float: left; /* 浮動向左 */ width: 33.33%; /* 每個item設置寬度是33.33% */ height: 120px; /* 每個item設置高度是120px */ text-align: center; /* 設置圖片下方的提示文字居中顯示 */ } /* 4.3. 右側(cè)欄中的每個item的圖樣式設置 */ .nav_right .nav_right_items image{ width: 60px; /* 給圖片設置寬度 */ height: 60px; /* 給圖片設置高度 */ margin-top: 15px; /* 圖片距離上邊距15px */ border-radius: 40%; /* 給圖片添加圓角邊框 */ }
更多教程點擊《Vue.js前端組件學習教程》,歡迎大家學習閱讀。
關(guān)于vue.js組件的教程,請大家點擊專題vue.js組件學習教程進行學習。
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。