微信小程序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è)展示頁面分為上下兩層
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è)展示頁面---> <view class="page-top {{open ? 'page-state' : ''}}"> <----上層右側(cè)展示頁面遮罩層---> <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({ /** * 頁面的初始數(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í)長 }, //列表的操作函數(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來改變動(dòng)畫的控制—-減少了js對dom中style的操作。
2. 在左側(cè)菜單導(dǎo)航操作的最后記得open=false
,使頁面還原。
DEMO源碼
點(diǎn)擊此處本站下載。
希望本文所述對大家微信小程序開發(fā)有所幫助。
- 微信小程序MUI側(cè)滑導(dǎo)航菜單示例(Popup彈出式,左側(cè)滑動(dòng),右側(cè)不動(dòng))
- 微信小程序左滑動(dòng)顯示菜單功能的實(shí)現(xiàn)
- 微信小程序圖片橫向左右滑動(dòng)案例
- 微信小程序左右滑動(dòng)切換頁面詳解及實(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í)現(xiàn)求浮點(diǎn)數(shù)的平方根【遞歸原理】
這篇文章主要介紹了javascript基于牛頓迭代法實(shí)現(xiàn)求浮點(diǎn)數(shù)的平方根,簡單說明了牛頓迭代法的原理,并結(jié)合實(shí)例分析了javascript基于遞歸的數(shù)值運(yùn)算相關(guān)操作技巧,需要的朋友可以參考下2017-09-09純javascript前端實(shí)現(xiàn)base64圖片下載(兼容IE10+)
這篇文章主要介紹了純javascript前端實(shí)現(xiàn)base64圖片下載(兼容IE10+),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-09-09JS利用正則表達(dá)式實(shí)現(xiàn)簡單的密碼強(qiáng)弱判斷實(shí)例
這篇文章主要給大家介紹了關(guān)于JS利用正則表達(dá)式實(shí)現(xiàn)簡單的密碼強(qiáng)弱判斷的相關(guān)資料,實(shí)現(xiàn)后的效果非常簡單,但也挺實(shí)用的,文中給出了詳細(xì)的示例代碼供大家參考學(xué)習(xí),需要的朋友們下面來一起看看吧。2017-06-06JavaScript在web自動(dòng)化測試中的作用示例詳解
這篇文章主要給大家介紹了關(guān)于JavaScript在web自動(dòng)化測試中的作用的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用JavaScript具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08javaScript手機(jī)號(hào)碼校驗(yàn)工具類PhoneUtils詳解
這篇文章主要為大家詳細(xì)介紹了javaScript手機(jī)號(hào)碼校驗(yàn)工具類PhoneUtils,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-12-12TypeScript工具類 Partial 和 Required 的場景分析
這篇文章主要介紹了TypeScript工具類 Partial 和 Required 的詳細(xì)講解,本文通過場景描述給大家詳細(xì)講解工具類的使用,結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2022-09-09