微信小程序MUI側(cè)滑導(dǎo)航菜單示例(Popup彈出式,左側(cè)滑動(dòng),右側(cè)不動(dòng))
本文實(shí)例講述了微信小程序MUI側(cè)滑導(dǎo)航菜單。分享給大家供大家參考,具體如下:
實(shí)現(xiàn)的目標(biāo)MUI的off canvas效果
點(diǎn)擊列表 —- 右側(cè)展示頁(yè)面不動(dòng),左側(cè)導(dǎo)航滑動(dòng) —- 點(diǎn)擊右側(cè)遮罩層或者左側(cè)選項(xiàng) —- 左側(cè)還原,右側(cè)去掉遮罩層
實(shí)現(xiàn)方案2:左右分上下兩層,左側(cè)滑動(dòng),右側(cè)不動(dòng)

WXML
<view class="page">
<view class="page-top {{open ? 'page-top-show' : ''}}">
<view class="nav-list" wx:for-items="{{nav_list}}" bindtap="open_list" data-title="{{item}}">
<text>{{item}}</text>
</view>
</view>
<view class="page-bottom">
<image class="off-nav-list" bindtap="off_canvas" src="../../images/btn.png"></image>
<view class="page-bottom-content">
<text>{{text}}</text>
</view>
<view class="page-mask {{open ? '' : 'page-mask-hide'}}" bindtap="off_canvas"></view>
</view>
</view>
WXSS
page,.page {
height: 100%;
font-family: 'PingFang SC', 'Helvetica Neue', Helvetica, 'Droid Sans Fallback', 'Microsoft Yahei', sans-serif;
}
/*左側(cè)導(dǎo)航 */
.page-top{
position: fixed;
width: 75%;
height: 100%;
top: 0;
left: 0;
background-color: rgb(0, 68, 97);
transform: rotate(0deg) scale(1) translate(-100%,0%);
-webkit-transform: rotate(0deg) scale(1) translate(-100%,0%);
transition: all 0.4s ease;
z-index: 998;
}
.page-top-show{
transform: rotate(0deg) scale(1) translate(0%,0%);
-webkit-transform: rotate(0deg) scale(1) translate(0%,0%);
}
.nav-list{
padding: 30rpx 0 30rpx 40rpx;
color:#fff;
}
/*右側(cè)展示 */
.page-bottom{
height: 100%;
background-color: rgb(57, 125, 230);
position: relative;
}
.off-nav-list{
position: fixed;
width: 60rpx;
height: 50rpx;
top: 20rpx;
left:20rpx;
}
.page-bottom-content{
padding:100rpx 20rpx 30rpx;
color: #fff;
}
.page-mask{
width: 100%;
height: 100%;
background-color:rgba(0,0,0,0.5);
position: absolute;
top: 0;
left: 0;
z-index: 10;
}
.page-mask-hide{
display: none;
}
JS
var app = getApp();
var data = require('../../utils/data.js');
Page({
/**
* 頁(yè)面的初始數(shù)據(jù)
*/
data: {
text: 'ES6學(xué)習(xí)之路',
nav_list: ['ES6學(xué)習(xí)之路', 'CSS特效', 'VUE實(shí)戰(zhàn)','微信小程序'],
open: false
},
//列表的操作函數(shù)
open_list: function(opts){
this.setData({ text: opts.currentTarget.dataset.title,open: false});
},
//左側(cè)導(dǎo)航的開(kāi)關(guān)函數(shù)
off_canvas: function(){
this.data.open ? this.setData({open: false}) :this.setData({open: true});
}
})
總結(jié):
1. 代碼簡(jiǎn)化:off_canvas函數(shù)簡(jiǎn)化代碼,采用三目表達(dá)式,簡(jiǎn)單切清晰;
2. 渲染:注意對(duì)data對(duì)象中屬性進(jìn)行賦值時(shí),要采用this.setData()方法,否則屬性改變不會(huì)重新渲染(eg:this.data.text = opts.currentTarget.dataset.title;)這樣text的值改變,頁(yè)面不會(huì)重新渲染text;
3. 代碼簡(jiǎn)化:this.data.open ? this.setData({open: false}) :this.setData({open: true});簡(jiǎn)化為this.setData({ open: this.data.open ? false : true});
希望本文所述對(duì)大家微信小程序開(kāi)發(fā)有所幫助。
- 微信小程序MUI側(cè)滑導(dǎo)航菜單示例(Popup彈出式,左側(cè)不動(dòng),右側(cè)滑動(dòng))
- 微信小程序左滑動(dòng)顯示菜單功能的實(shí)現(xiàn)
- 微信小程序圖片橫向左右滑動(dòng)案例
- 微信小程序左右滑動(dòng)切換頁(yè)面詳解及實(shí)例代碼
- 微信小程序側(cè)邊欄滑動(dòng)特效(左右滑動(dòng))
- 微信小程序左右滑動(dòng)的實(shí)現(xiàn)代碼
- 微信小程序 向左滑動(dòng)刪除功能的實(shí)現(xiàn)
- 微信小程序滾動(dòng)Tab實(shí)現(xiàn)左右可滑動(dòng)切換
- 微信小程序?qū)崿F(xiàn)左側(cè)滑動(dòng)導(dǎo)航欄
- 微信小程序?qū)崿F(xiàn)點(diǎn)餐小程序左側(cè)滑動(dòng)菜單
相關(guān)文章
JS Excel讀取和寫入操作(模板操作)實(shí)現(xiàn)代碼
前一段時(shí)間一直在做報(bào)表,所以肯定會(huì)用到Excel的操作,但是在網(wǎng)上查閱資料有關(guān)JS操作excel較少,有的話,也都是老生常談或很零碎的一些東西。2010-04-04
用原生JS實(shí)現(xiàn)簡(jiǎn)單的多選框功能
這篇文章主要介紹了用原生JS實(shí)現(xiàn)簡(jiǎn)單的多選框功能,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-06-06
js?Cannot?set?properties?of?null(setting?‘onclick‘)問(wèn)題分
今天增加功能的時(shí)候,提示Uncaught?TypeError:?Cannot?set?properties?of?null?(setting?onclick)問(wèn)題分享下,需要的朋友可以參考下2023-06-06
一文詳解JavaScript中的replace()函數(shù)
replace方法的語(yǔ)法是stringObj.replace(rgExp, replaceText),其中stringObj是字符串(string),下面這篇文章主要給大家介紹了關(guān)于JavaScript中replace()函數(shù)的相關(guān)資料,需要的朋友可以參考下2023-01-01
詳解JavaScript對(duì)Date對(duì)象的操作問(wèn)題(生成一個(gè)倒數(shù)7天的數(shù)組)
最近項(xiàng)目需求要生成一個(gè)倒數(shù)7天的數(shù)組,下面小編把我的實(shí)現(xiàn)思路和代碼整理分享給大家,供大家參考,需要的朋友可以參考下2015-10-10

