微信小程序?qū)崿F(xiàn)聯(lián)動(dòng)菜單
最近為了實(shí)現(xiàn)課程設(shè)計(jì),也做了一些前端的東西,今天想要做一個(gè)聯(lián)動(dòng)菜單來實(shí)現(xiàn)一些功能。實(shí)現(xiàn)了,也來做做筆記。
第1步:了解一下
左右側(cè)菜單其實(shí)簡單來講就是把一個(gè)區(qū)域分成左右兩個(gè)部分。關(guān)于組件,我覺得可以直接去微信開發(fā)文檔看。通過代碼,我覺得應(yīng)該是可以理解的。話步多講,直接上代碼。(首先說明一點(diǎn)的是,我還是個(gè)剛剛接觸前端的小白,可能有些寫得不太好得,往各位博友多多指出改進(jìn)得建議,相互學(xué)習(xí))
第2步:先看一下效果啦


運(yùn)行效率還是可以的很快,無卡頓現(xiàn)象。
第3步:實(shí)現(xiàn)(代碼)
這里我只放了其中一部分,也是可以直接實(shí)現(xiàn)的,沒有問題,可以根據(jù)自己的需要修改。
wxml
<!-- 左側(cè)滾動(dòng)欄 -->
<view class ='total'>
<view class='under_line'></view>
<view style='float: left' class='left'>
<scroll-view scroll-y scroll-with-animation scroll-left="{{scrollLength}}" class='scrollY' style='height: {{winHeight}}px'>
<view class='all clear'>
<block wx:key="lists" wx:for="{{lists}}">
<view bindtap='jumpIndex' data-menuindex='{{index}}'>
<view class='text-style'>
<text class="{{indexId==index?'active1':''}}">{{item}}</text>
<text class="{{indexId==index?'active':''}}"></text>
</view>
</view>
</block>
</view>
</scroll-view>
</view>
<!--右側(cè)欄-->
<view class="right">
<!--判斷indexId值顯示不同頁面-->
<view wx:if="{{indexId==0}}">
<scroll-view scroll-y scroll-with-animation scroll-left="{{scrollLength}}" class='scrollY2' style='height: {{winHeight}}px'>
<view class='all clear'>
<block wx:key="lists_r0" wx:for="{{lists_r0}}">
<view bindtap='jumpIndexR0' data-menuindex='{{index}}'>
<view class='text-style2'>
<text class="{{indexIdr0==index?'active2':''}}">{{item}}</text>
<text class="{{indexIdr0==index?'active3':''}}"></text>
</view>
</view>
</block>
</view>
</scroll-view>
</view>
<view wx:if="{{indexId==1}}">
<scroll-view scroll-y scroll-with-animation scroll-left="{{scrollLength}}" class='scrollY2' style='height: {{winHeight}}px'>
<view class='all clear'>
<block wx:key="lists_r1" wx:for="{{lists_r1}}">
<view bindtap='jumpIndexR0' data-menuindex='{{index}}'>
<view class='text-style2'>
<text class="{{indexIdr0==index?'active2':''}}">{{item}}</text>
<text class="{{indexIdr0==index?'active3':''}}"></text>
</view>
</view>
</block>
</view>
</scroll-view>
</view>
</view>
</view>
wxss
.under_line{
width: 100%;
border-top: 1rpx solid #efefef;
}
.left {
border-top: 1rpx solid #efefef;
border-right: 1rpx solid #efefef;
}
.text-style {
width: 200rpx;
height: 140rpx;
line-height: 140rpx;
text-align: center;
font-size: 34rpx;
font-family: PingFangSC-Semibold;
color: rgba(51, 51, 51, 1);
}
.active3 {
display: block;
width: 500rpx;
height: 6rpx;
background: rgb(88, 123, 193);
position: relative;
left: 0rpx;
bottom: 30rpx;
}
.active2 {
color: rgb(88, 123, 193);
}
.active1 {
color: #96C158;
}
.active {
display: block;
width: 50rpx;
height: 6rpx;
background: #96C158;
position: relative;
left: 75rpx;
bottom: 30rpx;
}
.scrollY {
width: 210rpx;
position: fixed;
left: 0;
top: 0;
border-right: 1rpx solid #efefef;
}
.right{
border-top: 1rpx solid #efefef;
border-left: 1rpx solid rgba(0,0,0,0.0);
margin-left: 2rpx;
}
.scrollY2 {
width: 520rpx;
position: fixed;
right: 0;
top: 0;
border-left: 1rpx solid rgba(0,0,0,0);
margin-left: 2rpx;
}
.text-style2 {
width: 520rpx;
height: 140rpx;
line-height: 140rpx;
text-align: left;
font-size: 34rpx;
font-family: PingFangSC-Semibold;
color: rgba(51, 51, 51, 1);
}
.button_call{
height: 90rpx;
width: 90rpx;
position: fixed;
bottom: 150rpx;
right: 13rpx;
opacity: 0.7;
z-index: 100;
}
js
Page({
/**
* 頁面的初始數(shù)據(jù)
*/
data: {
lists: [
"主類1", "主類2", "主類3", "學(xué)生工作部", "黨委部門", "校工與教務(wù)", "離退休工作處", "保衛(wèi)處", "財(cái)務(wù)與審計(jì)", "實(shí)驗(yàn)室與設(shè)備", "人事處", "保衛(wèi)處", "學(xué)院", "直屬單位", "其他"
],
lists_r0: [
"主類1的子類1",
"主類1的子類2", "主類1的子類3", "主類1的子類4", "黨委部門", "校工與教務(wù)", "離退休工作處", "保衛(wèi)處", "財(cái)務(wù)與審計(jì)", "實(shí)驗(yàn)室與設(shè)備", "人事處", "保衛(wèi)處", "學(xué)院", "直屬單位", "其他"
],
lists_r1: [
"主類2的子類1",
"主類2的子類2", "主類2的子類3", "主類2的子類4", "黨委部門", "校工與教務(wù)", "離退休工作處", "保衛(wèi)處", "財(cái)務(wù)與審計(jì)", "實(shí)驗(yàn)室與設(shè)備", "人事處", "保衛(wèi)處", "學(xué)院", "直屬單位", "其他"
],
indexId: 0,
indexIdr0: 0,
indexIdr0: 1,
},
// 左側(cè)點(diǎn)擊事件
jumpIndex(e) {
let index = e.currentTarget.dataset.menuindex
let that = this
that.setData({
indexId: index
});
},
jumpIndexR0(e) {
let index = e.currentTarget.dataset.menuindex
let that = this
that.setData({
indexIdr0: index
});
},
/**
* 生命周期函數(shù)--監(jiān)聽頁面加載
*/
onLoad: function(options) {
var that = this
wx.getSystemInfo({
success: function(res) {
that.setData({
winHeight: res.windowHeight
});
}
});
},
/**
* 生命周期函數(shù)--監(jiān)聽頁面初次渲染完成
*/
onReady: function() {
},
/**
* 生命周期函數(shù)--監(jiān)聽頁面顯示
*/
onShow: function() {
},
/**
* 生命周期函數(shù)--監(jiān)聽頁面隱藏
*/
onHide: function() {
},
/**
* 生命周期函數(shù)--監(jiān)聽頁面卸載
*/
onUnload: function() {
},
/**
* 頁面相關(guān)事件處理函數(shù)--監(jiān)聽用戶下拉動(dòng)作
*/
onPullDownRefresh: function() {
},
/**
* 頁面上拉觸底事件的處理函數(shù)
*/
onReachBottom: function() {
},
/**
* 用戶點(diǎn)擊右上角分享
*/
onShareAppMessage: function() {
}
})
json
{
"usingComponents": { },
"navigationBarBackgroundColor":"自己想要的背景色",
"navigationBarTitleText": "電話查詢",
"navigationBarTextStyle":"black",
"enablePullDownRefresh": true
}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 微信小程序?qū)崿F(xiàn)菜單左右聯(lián)動(dòng)
- 微信小程序scroll-view實(shí)現(xiàn)左右聯(lián)動(dòng)效果
- 微信小程序?qū)崿F(xiàn)左右聯(lián)動(dòng)
- 微信小程序scroll-view實(shí)現(xiàn)左右聯(lián)動(dòng)
- 微信小程序?qū)崿F(xiàn)購物頁面左右聯(lián)動(dòng)
- 微信小程序?qū)崿F(xiàn)左右列表聯(lián)動(dòng)
- 微信小程序?qū)崿F(xiàn)左右聯(lián)動(dòng)的實(shí)戰(zhàn)記錄
- 微信小程序?qū)崿F(xiàn)菜單左右聯(lián)動(dòng)效果
相關(guān)文章
JavaScript實(shí)現(xiàn)輸入框(密碼框)出現(xiàn)提示語
有時(shí)候我們需要在登陸表單有一些提示語言,比如“請輸入用戶名”和“請輸入密碼”等語言,通過本文給大家介紹JavaScript實(shí)現(xiàn)輸入框(密碼框)出現(xiàn)提示語的相關(guān)知識(shí),對js實(shí)現(xiàn)輸入框提示相關(guān)知識(shí)感興趣的朋友一起學(xué)習(xí)吧2016-01-01
基于Javascript實(shí)現(xiàn)文件實(shí)時(shí)加載進(jìn)度的方法
不知道大家有沒有發(fā)現(xiàn)在現(xiàn)在的移動(dòng)頁面上,有很多情況需要加載大量的資源。但是移動(dòng)端的訪問速度和pc還是有很大的差距,有些時(shí)候需要一些取巧的方式來提升用戶體驗(yàn),而實(shí)時(shí)顯示加載進(jìn)度就是其中一種。這篇文章就給大家分享了Javascript實(shí)現(xiàn)文件實(shí)時(shí)加載進(jìn)度的方法。2016-10-10
用幾道面試題來看JavaScript執(zhí)行機(jī)制
這篇文章主要介紹了JavaScript的執(zhí)行機(jī)制,對此感興趣的同學(xué),可以參考下2021-04-04
通過隱藏iframe實(shí)現(xiàn)無刷新上傳文件操作
本文給大家介紹iframe無刷新上傳文件,通過一個(gè)隱藏的iframe來處理上傳操作我采用的是ReactJS,amazeui,nodejs1.html target指向iframe的name,就是把上傳后的操作交給iframe來處理2016-03-03
JavaScript 組件之旅(四):測試 JavaScript 組件
本期,我們要討論的話題是 JavaScript 的測試,以檢查組件的狀態(tài)和工作方式是否符合預(yù)期,還會(huì)介紹一個(gè)可以方便編寫測試用例的測試方法。這里說的測試當(dāng)然是使用自動(dòng)化的測試手段,這是軟件質(zhì)量保證(QA)的重要環(huán)節(jié)。2009-10-10
JavaScript 數(shù)組運(yùn)用實(shí)現(xiàn)代碼
復(fù)習(xí)一下JS中數(shù)組的運(yùn)用。學(xué)習(xí)js數(shù)組的朋友可以參考下。2010-04-04
JS判斷元素是否存在數(shù)組中的5種方式總結(jié)
數(shù)組是我們編程中經(jīng)常使用的的數(shù)據(jù)結(jié)構(gòu)之一,在處理數(shù)組時(shí)我們經(jīng)常需要在數(shù)組中查找特定的值,下面這篇文章主要給大家總結(jié)介紹了關(guān)于JS判斷元素是否存在數(shù)組中的5種方式,需要的朋友可以參考下2023-03-03
Bootstrap時(shí)間選擇器datetimepicker和daterangepicker使用實(shí)例解析
這篇文章主要為大家詳細(xì)解析了Bootstrap時(shí)間選擇器datetimepicker和daterangepicker使用實(shí)例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09

