小程序CSS实现抽屉式按钮弹出拉伸特效

2018-11-18  本文已影响0人  afishtail

先上效果图

效果图

实现思路及问题

下面是代码

index.wxml

<view class='pop-box {{unfold==0?"on":""}} {{unfold==1?"off":""}}'>
  <view bindtap='unfold'>点我</view>
  <view>222</view>
  <view>333</view>
</view>

index.wxss

.pop-box {
  width: 120rpx;
  height: 120rpx;
  border: 1rpx solid pink;
  display: flex;
  flex-direction: column-reverse;
  justify-content: space-between;
  overflow: hidden;
  position: fixed;
  bottom: 100rpx;
  right: 50rpx;
}

.pop-box>view {
  width: 120rpx;
  height: 120rpx;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  flex: none;
}

.pop-box>view:nth-child(1) {
  background-color: rgb(243, 81, 17);
}

.pop-box>view:nth-child(2) {
  background-color: rgb(192, 255, 245);
}

.pop-box>view:nth-child(3) {
  background-color: rgb(128, 32, 218);
}

@keyframes unfold {
  0% {
    height: 120rpx;
  }

  80% {
    height: 500rpx;
  }

  100% {
    height: 420rpx;
  }
}

@keyframes shrink {
  0% {
    height: 420rpx;
  }

  20% {
    height: 500rpx;
  }

  100% {
    height: 420rpx;
  }
}
.on {
  height: 420rpx;
  animation: unfold 1.2s 1 ease-out;
}
.off {
  height: 120rpx;
  animation: shrink 1.2s 1 ease-out;
}

index.js

data: {
    unfold: null //0为展开,1为收缩
  },
    unfold() {
    var unfold = this.data.unfold
    if (unfold === null) { //默认为收缩
      unfold = 1   
    }
    if (unfold == 0) {   //点击后改变展开样式
      unfold = 1
    } else {
      unfold = 0
    }
    this.setData({  //赋值
      unfold: unfold
    })
  }

github

个人博客

上一篇 下一篇

猜你喜欢

热点阅读