微信小程序上下左右滑动动画

1.HTML

<view class='main' bindtap="show">{{text}}</view>
<view class="top {{showFlag?'showTop':''}}">我是顶部</view>
<view class="bottom {{showFlag?'showBottom':''}}">我是底部</view>
<view class="right {{showFlag?'showRight':''}}">我是右部</view>
<view class="left {{showFlag?'showLeft':''}}">我是左部</view>

2.css

page {
  background-color: #009eff;
  text-align: center;
  color: #333;
  height: 100%;
}

.main {
  position: fixed;
  top: 300rpx;
  bottom: 300rpx;
  left: 30%;
  width: 40%;
  background-color: red;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}
.top {
  position: fixed;
  top: 0;
  width: 100%;
  height: 300rpx;
  line-height: 300rpx;
  background-color: #fff;
  transform: translate3d(0,-100%,0);
  transition: all 0.2s;
  z-index: 10;
}
.showTop{
  transform: translate3d(0,0,0);
}

.bottom {
  position: fixed;
  bottom: 0;
  width: 100%;
  height: 300rpx;
  line-height: 300rpx;
  background-color: #fff;
  transform: translate3d(0,100%,0);
  transition: all 0.2s;
  z-index: 10;
}
.showBottom{
  transform: translate3d(0,0,0);
}
.right{
  position: fixed;
  right: 0;
  top: 0;
  width: 30%;
  height: 100%;
  line-height: 300rpx;
  background-color: #fff;
  transform: translate3d(100%,0,0);
  transition: all 0.2s;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
}
.showRight{
  transform: translate3d(0,0,0);
}
.left{
  position: fixed;
  left: 0;
  top: 0;
  width: 30%;
  height: 100%;
  line-height: 300rpx;
  background-color: #fff;
  transform: translate3d(-100%,0,0);
  transition: all 0.2s;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
}
.showLeft{
  transform: translate3d(0,0,0);
}

3.js

data: {
    text:"显示",
    showFlag:false
  },
show:function(){
    this.setData({
      showFlag: this.data.showFlag?false:true,
      text: this.data.showFlag ? "显示" : "隐藏"
    });
  }

4.效果图

刚开始的效果
正在运行时的效果
运行完的效果

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值