微信小程序-顶部提示框弹出动画

效果

思路 

参考CSS手册 http://www.w3school.com.cn/css3/css3_animation.asp 

用css的animation属性做动画

代码

wxml:

<view class="container">
  <view class='anit {{show?"show":""}}'>请选择商品</view>
  <view bindtap='anniu'>点击弹出提示</view>
</view>

wxss:

.container {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 200rpx 0;
  box-sizing: border-box;
} 
.anit{
  width: 100%;
  height: 70rpx;
  background: red;
  position: absolute;
  color: white;
  font-size: 30rpx;
  line-height: 70rpx;
  top: -70rpx;
  text-align: center;
}
.show{
  top: -70rpx;
  animation: show 2s;
  animation-timing-function:ease;
}
@keyframes show
{
  0% {top:-70rpx;}
  10% {top:0rpx;}
  80% {top:0rpx;}
  100% {top:-70rpx;}
}

js:

Page({
  data: {
    show: 0
  },

  onLoad: function () {

  },

  anniu: function (e) {
    if(!this.data.show){
      let that = this;
      this.setData({
        show: 1
      })
      setTimeout(function () {
        that.setData({
          show: 0
        })
      }, 2000)
    }
  }
})

 

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值