国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 課堂 > 小程序 > 正文

微信小程序開發實現自定義模態彈窗教程

2020-03-21 16:28:49
字體:
來源:轉載
供稿:網友

最近發現一個比較好用的小程序自定義模態框,將其簡化了一下,可以在框內放入想要的內容。

具體內容如下:

index.wxml
 

  1. <view class="btn" bindtap="powerDrawer" data-statu="open">button</view>   
  2.  
  3. <!--mask-->   
  4.  
  5. <view class="drawer_screen" bindtap="powerDrawer" data-statu="close" wx:if="{{showModalStatus}}"></view>   
  6.  
  7. <!--content-->   
  8.  
  9. <!--使用animation屬性指定需要執行的動畫-->   
  10.  
  11. <view animation="{{animationData}}" class="drawer_box" wx:if="{{showModalStatus}}">   
  12.  
  13.   <view class="drawer_title">彈窗標題</view>   
  14.  
  15.   <view class="drawer_content">   
  16.  
  17.   </view>   
  18.  
  19.   <view class="btn_ok" bindtap="powerDrawer" data-statu="close">確定</view>   
  20.  
  21. </view>   

index.wxss
 

  1. .btn {   
  2.  
  3.   width80%;   
  4.  
  5.   padding20rpx 0;   
  6.  
  7.   border-radius: 10rpx;   
  8.  
  9.   text-aligncenter;   
  10.  
  11.   margin40rpx 10%;   
  12.  
  13.   background#000;   
  14.  
  15.   color#fff;   
  16.  
  17. }   
  18.  
  19. /*mask*/   
  20.  
  21. .drawer_screen {   
  22.  
  23.   width100%;   
  24.  
  25.   height100%;   
  26.  
  27.   positionfixed;   
  28.  
  29.   top: 0;   
  30.  
  31.   left: 0;   
  32.  
  33.   z-index1000;   
  34.  
  35.   background#000;   
  36.  
  37.   opacity: 0.5;   
  38.  
  39.   overflowhidden;   
  40.  
  41. }   
  42.  
  43. /*content*/   
  44.  
  45. .drawer_box {   
  46.  
  47.   width650rpx;   
  48.  
  49.   overflowhidden;   
  50.  
  51.   positionfixed;   
  52.  
  53.   top: 50%;   
  54.  
  55.   left: 0;   
  56.  
  57.   z-index1001;   
  58.  
  59.   background#FAFAFA;   
  60.  
  61.   margin-150px 50rpx 0 50rpx;   
  62.  
  63.   border-radius: 3px;   
  64.  
  65. }   
  66.  
  67. .drawer_title{   
  68.  
  69.   padding:15px;   
  70.  
  71.   font20px "microsoft yahei";   
  72.  
  73.   text-aligncenter;   
  74.  
  75. }   
  76.  
  77. .drawer_content {   
  78.  
  79.   height210px;   
  80.  
  81.   overflow-y: scroll/*超出父盒子高度可滾動*/   
  82.  
  83. }   
  84.  
  85. .btn_ok{   
  86.  
  87.   padding10px;   
  88.  
  89.   font20px "microsoft yahei";   
  90.  
  91.   text-aligncenter;   
  92.  
  93.   border-top1px solid #E8E8EA;   
  94.  
  95.   color#3CC51F;   
  96.  
  97. }   

index.js
 

  1. Page({ 
  2.  
  3.   data: { 
  4.  
  5.     showModalStatus: false 
  6.  
  7.   }, 
  8.  
  9.   powerDrawer: function (e) { 
  10.  
  11.     var currentStatu = e.currentTarget.dataset.statu; 
  12.  
  13.     this.util(currentStatu) 
  14.  
  15.   }, 
  16.  
  17.   util: function (currentStatu) { 
  18.  
  19.     var animation = wx.createAnimation({ 
  20.  
  21.       duration: 200, 
  22.  
  23.       timingFunction: "linear",  
  24.  
  25.       delay: 0   
  26.  
  27.     }); 
  28.  
  29.     this.animation = animation; 
  30.  
  31.     animation.opacity(0).rotateX(-100).step(); 
  32.  
  33.     this.setData({ 
  34.  
  35.       animationData: animation.export() 
  36.  
  37.     }) 
  38.  
  39.     setTimeout(function () { 
  40.  
  41.       animation.opacity(1).rotateX(0).step(); 
  42.  
  43.       this.setData({ 
  44.  
  45.         animationData: animation 
  46.  
  47.       }) 
  48.  
  49.       if (currentStatu == "close") { 
  50.  
  51.         this.setData( 
  52.  
  53.           { 
  54.  
  55.             showModalStatus: false 
  56.  
  57.           } 
  58.  
  59.         ); 
  60.  
  61.       } 
  62.  
  63.     }.bind(this), 200) 
  64.  
  65.     if (currentStatu == "open") { 
  66.  
  67.       this.setData( 
  68.  
  69.         { 
  70.  
  71.           showModalStatus: true 
  72.  
  73.         } 
  74.  
  75.       ); 
  76.  
  77.     } 
  78.  
  79.   } 
  80.  
  81. })   

微信小程序,小程序開發,模態彈窗


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 自贡市| 华蓥市| 陕西省| 武乡县| 忻州市| 贡觉县| 武夷山市| 永胜县| 蓬安县| 林西县| 乌审旗| 深水埗区| 海兴县| 宁津县| 驻马店市| 共和县| 环江| 定西市| 玉林市| 菏泽市| 比如县| 北京市| 侯马市| 天长市| 伊川县| 韶山市| 醴陵市| 江源县| 台南市| 铜鼓县| 健康| 白银市| 金阳县| 漠河县| 靖远县| 桃园县| 株洲市| 辽阳市| 商洛市| 金山区| 左权县|