欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

微信小程序CSS3動畫下拉菜單效果

 更新時間:2018年11月04日 09:35:55   作者:PAT-python-zjw  
這篇文章主要為大家詳細(xì)介紹了微信小程序CSS3動畫下拉菜單效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下

微信小程序沒有自帶的下拉菜單組件,因此我們需要自己需要寫一個

思路

利用列表來存儲菜單項(xiàng),在外面套一個view元素作為外框,將其設(shè)置為overflow:hidden,使用CSS3動畫逐漸改變外層view元素的高度,當(dāng)高度為0時,里面嵌套的列表元素被完全隱藏,相當(dāng)于菜單關(guān)閉。而當(dāng)view元素的高度大于列表元素的高度時,相當(dāng)于菜單顯示。

效果圖

wxml

button按鈕用于觸發(fā)菜單的打開和關(guān)閉,first_click參數(shù)使用戶第一次點(diǎn)擊按鈕之前菜單不可見,state參數(shù)用于控制菜單的打開和關(guān)閉狀態(tài)

<view id="text_box">
   <text decode='true'>&nbsp;歷&nbsp;史&nbsp;記&nbsp;錄</text>
</view>
<button id="slide" bindtap="toggle">▼</button>
<view id="box" class="{{first_click?'show':'hide'}} {{state?'open':'close'}}">
   <view id="item_list">
      <view>111</view>
      <view>222</view>
      <view>333</view>
   </view>
</view>

css

使用@keyframes動畫實(shí)現(xiàn)菜單的漸變打開和關(guān)閉動畫

#box{
 width: 100%;
 border-top: 1px solid #ddd;
 overflow: hidden;
 height: 0;
 animation-fill-mode: forwards;
}

#item_list{
  background-color: white;
  width: 100%;
}

#item_list view{
  text-align: right;
  overflow: auto;
  white-space: nowrap;
}

@keyframes slidedown{
  from {
    height: 0;
  }
  to {
    height: 240rpx;
  }
}

@keyframes slideup{
  from {
    height: 240rpx;
  }
  to {
    height: 0;
  }
}

.open{
  animation: slidedown 1s;
}

.close{
  animation: slideup 1s; 
}

.hide{
  display: none;
}

.show{
  display: block;
}

js

頁面加載完成時,菜單初始狀態(tài)為隱藏和關(guān)閉,用戶一旦點(diǎn)擊按鈕,菜單就顯示,并逐漸打開

data: {
  state:false,
  first_click:false,
 },

 toggle: function(){
   var list_state = this.data.state,
     first_state = this.data.first_click;
   if (!first_state){
     this.setData({
      first_click: true
     });
   }
   if (list_state){
     this.setData({
      state: false
     });
   }else{
     this.setData({
      state: true
     });
   }
 }

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論