這篇文章主要為大家展示了“微信小程序模擬下拉菜單開發的示例分析”,內容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領大家一起研究并學習一下“微信小程序模擬下拉菜單開發的示例分析”這篇文章吧。
為察隅等地區用戶提供了全套網頁設計制作服務,及察隅網站建設行業解決方案。主營業務為做網站、成都網站制作、察隅網站設計,以傳統方式定制建設網站,并提供域名空間備案等一條龍服務,秉承以專業、用心的態度為用戶提供真誠的服務。我們深信只要達到每一位用戶的要求,就會得到認可,從而選擇與我們長期合作。這樣,我們也可以走得更遠!
本文主要和大家分享微信小程序模擬下拉菜單開發實例,希望能幫助到大家。
一.知識點
1.實現動態顯示和隱藏某個控件
<view class="{{open?'display_show':'display_none'}}">列表1</view>
data:{ open:false }, showitem:function(){ this.setData({ open:!this.data.open }) },
.display_show{ display: block; } .display_none{ display: none; }
2.通過 data-*
和 e.target.dateset
傳遞參數
<view class="phone_personal">{{firstPerson}}</view>
<view class="select_one" bindtap="mySelect" data-me="吃">吃</view>
this.setData({ firstPerson:e.target.dataset.me, })
這時:firstPerson=吃
3.彈性盒字:display:flex;
<view class="phone_one" bindtap="clickPerson"> <view class="phone_personal">{{firstPerson}}</view> <image src="../../image/i.png" class="personal_image {{selectArea ? 'rotateRight' :''}}"></image> </view>
在父級:
display:flex;
justify-content:space-between;
這樣子集就會并列。justify-content:space-between;這樣子集就會分別在在倆頭
二.事列
(1).下拉列表
1.wxml
<view class="page"> <view class="page_bd"> <view class="body_head" bindtap="showitem">點擊我顯示下拉列表</view> <navigator url="pages/list/list"> <view class="{{open?'display_show':'display_none'}}">列表1</view> </navigator> <navigator url="pages/scroll-view/index"> <view class="{{open?'display_show':'display_none'}}">列表2</view> </navigator> <navigator url="pages/scroll-view/index"> <view class="{{open?'display_show':'display_none'}}">列表3</view> </navigator> </view> </view>
2.wxss
.page_bd{ padding: 10px; background-color: snow; } .body_head{ border: 1px solid; border-color: beige; padding: 10px; } .display_show{ display: block; border: 1px solid; border-color: beige; padding: 10px; } .display_none{ display: none; }
3.js
Page({ data:{ open:false }, showitem:function(){ this.setData({ open:!this.data.open }) }, onLoad:function(options){ // 頁面初始化 options為頁面跳轉所帶來的參數 }, onReady:function(){ // 頁面渲染完成 }, onShow:function(){ // 頁面顯示 }, onHide:function(){ // 頁面隱藏 }, onUnload:function(){ // 頁面關閉 } })
(2).下拉菜單
1.wxml
<view class="phone_one" bindtap="clickPerson"> <view class="phone_personal">{{firstPerson}}</view> <image src="../../image/i.png" class="personal_image {{selectArea ? 'rotateRight' :''}}"></image> </view> <view class="person_box"> <view class="phone_select" hidden="{{selectPerson}}"> <view class="select_one" bindtap="mySelect" data-me="吃">吃</view> <view class="select_one" bindtap="mySelect" data-me="喝">喝</view> <view class="select_one" bindtap="mySelect" data-me="玩">玩</view> </view> </view>
2.wxss
phone_personal{ width: 100%; color:rgb(34, 154, 181); height:100rpx; line-height:100rpx; text-align: center; } .phone_one{ display:flex; position:relative; justify-content:space-between; background-color:rgb(239, 239, 239); width:90%; height:100rpx; margin:22px auto; border-radius:10rpx; border-bottom:2rpx solid rgb(255, 255, 255); line-height:51px; padding-left:10px; } .person_box{ position: relative; } .phone_select{ margin-top:0; z-index: 100; position: absolute; } .select_one{ text-align: center; background-color:rgb(239, 239, 239); width:676rpx; height:100rpx; line-height:100rpx; margin:0 5%; border-bottom:2rpx solid rgb(255, 255, 255); } .personal_image{ z-index: 100; position: absolute; right:2.5%; width: 34rpx; height: 20rpx; margin:40rpx 20rpx 40rpx 0; transition: All 0.4s ease; -webkit-transition: All 0.4s ease; } .rotateRight{ transform: rotate(180deg); }
3.js
Page({ data:{ selectPerson:true, firstPerson:'興趣', selectArea:false, }, //點擊選擇類型 clickPerson:function(){ var selectPerson = this.data.selectPerson; if(selectPerson == true){ this.setData({ selectArea:true, selectPerson:false, }) }else{ this.setData({ selectArea:false, selectPerson:true, }) } } , //點擊切換 mySelect:function(e){ this.setData({ firstPerson:e.target.dataset.me, selectPerson:true, selectArea:false, }) }, onLoad:function(options){ // 頁面初始化 options為頁面跳轉所帶來的參數 }, onReady:function(){ // 頁面渲染完成 }, onShow:function(){ // 頁面顯示 }, onHide:function(){ // 頁面隱藏 }, onUnload:function(){ // 頁面關閉 } })
以上是“微信小程序模擬下拉菜單開發的示例分析”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注創新互聯行業資訊頻道!
文章標題:微信小程序模擬下拉菜單開發的示例分析
當前地址:http://m.2m8n56k.cn/article23/gpoecs.html
成都網站建設公司_創新互聯,為您提供網站建設、、自適應網站、企業建站、標簽優化、網站改版
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:[email protected]。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯