溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

微信小程序模擬下拉菜單開發(fā)的示例分析

發(fā)布時(shí)間:2021-06-08 10:48:46 來源:億速云 閱讀:224 作者:小新 欄目:移動(dòng)開發(fā)

這篇文章主要為大家展示了“微信小程序模擬下拉菜單開發(fā)的示例分析”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“微信小程序模擬下拉菜單開發(fā)的示例分析”這篇文章吧。

本文主要和大家分享微信小程序模擬下拉菜單開發(fā)實(shí)例,希望能幫助到大家。

一.知識點(diǎn)

1.實(shí)現(xiàn)動(dòng)態(tài)顯示和隱藏某個(gè)控件

<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 傳遞參數(shù)

<view class="phone_personal">{{firstPerson}}</view>

<view class="select_one" bindtap="mySelect" data-me="吃">吃</view>

    this.setData({
             firstPerson:e.target.dataset.me,
       })

這時(shí):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;

這樣子集就會(huì)并列。justify-content:space-between;這樣子集就會(huì)分別在在倆頭

二.事列

(1).下拉列表

1.wxml

<view class="page">
    <view class="page_bd">
        <view class="body_head" bindtap="showitem">點(diǎn)擊我顯示下拉列表</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為頁面跳轉(zhuǎn)所帶來的參數(shù)
  },
  onReady:function(){
    // 頁面渲染完成
  },
  onShow:function(){
    // 頁面顯示
  },
  onHide:function(){
    // 頁面隱藏
  },
  onUnload:function(){
    // 頁面關(guān)閉
  }
})

微信小程序模擬下拉菜單開發(fā)的示例分析

(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,
  },
  //點(diǎn)擊選擇類型
  clickPerson:function(){
    var selectPerson = this.data.selectPerson;
    if(selectPerson == true){
        this.setData({
        selectArea:true,
        selectPerson:false,
      })
    }else{
      this.setData({
        selectArea:false,
        selectPerson:true,
      })
    }
  } ,
  //點(diǎn)擊切換
  mySelect:function(e){
    this.setData({
      firstPerson:e.target.dataset.me,
      selectPerson:true,
      selectArea:false,
    })
  },
  onLoad:function(options){
  // 頁面初始化 options為頁面跳轉(zhuǎn)所帶來的參數(shù)
  },
  onReady:function(){
  // 頁面渲染完成
  },
  onShow:function(){
  // 頁面顯示
  },
  onHide:function(){
  // 頁面隱藏
  },
  onUnload:function(){
  // 頁面關(guān)閉
  }
})

微信小程序模擬下拉菜單開發(fā)的示例分析

以上是“微信小程序模擬下拉菜單開發(fā)的示例分析”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI