欢迎来到258分享网,纯净的网络源码分享基地!

258资源分享网

全部作品
全部作品
网站源码
微信源码
素材特效
源码插件
视频教程
建站学院
热门搜索: 织梦  农业种植  农业  安全设置  官方
258资源分享 > 建站学院 > 微信开发 > 微信小程序之自定义抽屉菜单(从下拉出)实例

推荐下载

HTML5响应式自适应网咯设计

2020-05-12   浏览:740

高端HTML5响应式企业通用网

2020-05-06   浏览:521

html5响应式外贸网站英文版

2020-05-08   浏览:510

HTML5自适应律师工作室类网

2020-04-04   浏览:505

HTML5影视传媒文化公司类网

2020-05-12   浏览:502

微信小程序之自定义抽屉菜单(从下拉出)实例

发布时间:2021-01-07  

微信提供了动画api,就是下面这个

微信小程序之自定义抽屉菜单(从下拉出)实例

相关链接:https://mp.weixin.qq.com/debug/wxadoc/dev/api/api-animation.html#wxcreateanimationobject

通过使用这个创建动画的api,可以做出很多特效出来

下面介绍一个抽屉菜单的案例

实现代码:

wxml:

[html] view plain copy

 

<!--button-->  

<view class="btn" bindtap="powerDrawer" data-statu="open">button</view>  

<!--mask-->  

<view class="drawer_screen" bindtap="powerDrawer" data-statu="close" wx:if="{{showModalStatus}}"></view>  

<!--content-->  

<!--使用animation属性指定需要执行的动画-->  

<view animation="{{animationData}}" class="drawer_attr_box" wx:if="{{showModalStatus}}">  

  <!--drawer content-->  

  <view class="drawer_content">  

    <view class="drawer_title line">菜单1</view>  

    <view class="drawer_title line">菜单2</view>  

    <view class="drawer_title line">菜单3</view>  

    <view class="drawer_title line">菜单4</view>  

    <view class="drawer_title">菜单5</view>  

  </view>  

</view>  

 

wxss

[css] view plain copy

 

/*button*/  

.btn {  

  width80%;  

  padding20rpx 0;  

  border-radius: 10rpx;  

  text-aligncenter;  

  margin40rpx 10%;  

  background#0C1939;  

  color#fff;  

}  

/*mask*/  

.drawer_screen {  

  width100%;  

  height100%;  

  positionfixed;  

  top: 0;  

  left: 0;  

  z-index1000;  

  background#000;  

  opacity: 0.2;  

  overflowhidden;  

}  

/*content*/  

.drawer_attr_box {  

  width100%;  

  overflowhidden;  

  positionfixed;  

  bottom: 0;  

  left: 0;  

  z-index1001;  

  background#fff;  

}  

.drawer_content {  

  padding20rpx 40rpx;  

  height470rpx;  

  overflow-y: scroll;  

}  

.drawer_title{  

  padding:20rpx;  

  font:42rpx "microsoft yahei";  

  text-aligncenter;  

}  

.line{  

  border-bottom1px solid #f8f8f8;  

}  

 

js

[javascript] view plain copy

 

Page({  

  data: {  

    showModalStatus: false  

  },  

  powerDrawer: function (e) {  

    var currentStatu = e.currentTarget.dataset.statu;  

    this.util(currentStatu)  

  },  

  util: function(currentStatu){  

    /* 动画部分 */  

    // 第1步:创建动画实例   

    var animation = wx.createAnimation({  

      duration: 200,  //动画时长  

      timingFunction: "linear"//线性  

      delay: 0  //0则不延迟  

    });  

      

    // 第2步:这个动画实例赋给当前的动画实例  

    this.animation = animation;  

  

    // 第3步:执行第一组动画:Y轴偏移240px后(盒子高度是240px),停  

    animation.translateY(240).step();  

  

    // 第4步:导出动画对象赋给数据对象储存  

    this.setData({  

      animationData: animation.export()  

    })  

      

    // 第5步:设置定时器到指定时候后,执行第二组动画  

    setTimeout(function () {  

      // 执行第二组动画:Y轴不偏移,停  

      animation.translateY(0).step()  

      // 给数据对象储存的第一组动画,更替为执行完第二组动画的动画对象  

      this.setData({  

        animationData: animation  

      })  

        

      //关闭抽屉  

      if (currentStatu == "close") {  

        this.setData(  

          {  

            showModalStatus: false  

          }  

        );  

      }  

    }.bind(this), 200)  

    

    // 显示抽屉  

    if (currentStatu == "open") {  

      this.setData(  

        {  

          showModalStatus: true  

        }  

      );  

    }  

  }  

})  


效果: