微信小程序MUI側(cè)滑導(dǎo)航菜單示例(Popup彈出式,左側(cè)不動(dòng),右側(cè)滑動(dòng))
本文實(shí)例講述了微信小程序MUI側(cè)滑導(dǎo)航菜單。分享給大家供大家參考,具體如下:
實(shí)現(xiàn)的目標(biāo)—-YDUI的Popup組件
點(diǎn)擊列表圖標(biāo)—-左側(cè)的菜單欄顯示—-點(diǎn)擊關(guān)閉按鈕或者右側(cè)的遮罩層—-左側(cè)菜單欄關(guān)閉
實(shí)現(xiàn)方案1:左側(cè)菜單和右側(cè)展示頁(yè)面分為上下兩層

wxml
<view class="page">
<----下層左側(cè)導(dǎo)航--->
<view class="page-bottom">
<view class="page-content">
<view bindtap="open_list" wx:for-items="{{nav_list}}" class="page-list">
<text>{{item}}</text>
</view>
</view>
</view>
<----上層右側(cè)展示頁(yè)面--->
<view class="page-top {{open ? 'page-state' : ''}}">
<----上層右側(cè)展示頁(yè)面遮罩層--->
<view class="page-mask {{open ? '' : 'page-mask-show'}}" bindtap="offCanvas"></view>
<----列表按鈕--->
<image class="left-nav" bindtap="offCanvas" src="../../images/btn.png"></image>
<----輪播代碼,可以不要--->
<scroll-view scroll-y="true" style="height:200px" class="page-body" bindscrolltolower="loadMore">
<view class="swiper">
<swiper class="swiper-box" indicator-dots="{{indicatorDots}}" vertical="{{vertical}}"
autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}"
indicator-color="#fff" indicator-active-color="red">
<block wx:for-items="{{banner_url}}" wx:key="item.id">
<navigator url="../blogList/blogList">
<swiper-item>
<block wx:if="{{item}}">
<image class="imgw" src="{{item.url}}" mode="aspectFill"/>
</block>
<block wx:else>
<image src="../../images/default_pic.png" mode="aspectFill"></image>
</block>
</swiper-item>
</navigator>
</block>
</swiper>
</view>
</scroll-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-bottom{
height: 100%;
width: 75%;
position: fixed;
background-color: rgb(0, 68, 97);
z-index: 0;
}
.page-list{
color: white;
padding: 30rpx 0 30rpx 40rpx;
}
/*右側(cè)展示層 */
.page-top{
position: relative;
top: 0;
left:0;
width: 750rpx;
height: 100%;
background-color: rgb(57, 125, 230);
z-index: 0;
transition: All 0.4s ease;
-webkit-transition: All 0.4s ease;
}
.page-state{
transform: rotate(0deg) scale(1) translate(75%,0%);
-webkit-transform: rotate(0deg) scale(1) translate(75%,0%);
}
.imgw{width:100%;}
/*右側(cè)列表按鈕 */
.page-top .left-nav{
position: fixed;
width: 68rpx;
height: 38rpx;
left: 20rpx;
bottom: 20rpx;
}
/*右側(cè)遮罩層 */
.page-mask{
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
background-color: rgba(0,0,0,0.5);
z-index: 998;
}
.page-mask-show{
display: none;
}
js
var app = getApp();
var data = require('../../utils/data.js');
Page({
/**
* 頁(yè)面的初始數(shù)據(jù)
*/
data: {
banner_url: data.bannerList(),
nav_list: ['ES6學(xué)習(xí)之路', 'CSS特效', 'VUE實(shí)戰(zhàn)','微信小程序'],
open: false,
indicatorDots: true,//是否顯示面板指示點(diǎn)
autoplay: true,//是否開啟自動(dòng)切換
interval: 3000,//自動(dòng)切換時(shí)間間隔
duration: 500//滑動(dòng)動(dòng)畫時(shí)長(zhǎng)
},
//列表的操作函數(shù)
open_list: function(){
//此處進(jìn)行操作
this.setData({
open: false
});
},
//左側(cè)導(dǎo)航的開關(guān)函數(shù)
offCanvas: function(){
if(this.data.open){
this.setData({
open: false
});
}else{
this.setData({
open: true
});
}
}
})
總結(jié):
1. 右側(cè)展示的動(dòng)畫,我們可以直接通過class將其統(tǒng)一定義完整,然后通過切換class來(lái)改變動(dòng)畫的控制—-減少了js對(duì)dom中style的操作。
2. 在左側(cè)菜單導(dǎo)航操作的最后記得open=false,使頁(yè)面還原。
DEMO源碼
點(diǎn)擊此處本站下載。
希望本文所述對(duì)大家微信小程序開發(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)文章
JavaScript樹型數(shù)據(jù)與一維數(shù)組相互轉(zhuǎn)換方式
這篇文章主要介紹了JavaScript樹型數(shù)據(jù)與一維數(shù)組相互轉(zhuǎn)換方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-06-06
JavaScript中輸出</script>標(biāo)簽的方法
這篇文章主要介紹了JavaScript中輸出</script>標(biāo)簽的方法,在一些廣告代碼中經(jīng)常會(huì)用到這個(gè)小技巧,需要的朋友可以參考下2014-08-08
javascript簡(jiǎn)單實(shí)現(xiàn)表格行間隔顯示顏色并高亮顯示
表格行間隔顯示顏色并實(shí)現(xiàn)高亮顯示,這種效果大家都有見到過吧,下面就為大家詳細(xì)介紹下,需要的朋友可不要錯(cuò)過2013-11-11

