麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

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

微信小程序帶動畫彈窗組件使用方法詳解

2020-03-21 16:06:03
字體:
供稿:網(wǎng)友

本文實例為大家分享了微信小程序帶動畫彈窗的具體代碼,供大家參考,具體內(nèi)容如下

基本效果如下:

微信小程序,動畫,彈窗組件

具體實現(xiàn)如下:

第一步:

新建一個 components 文件夾,用于存放我們以后開發(fā)中的所用組件,在 components 組件中新建一個popup文件夾來存放我們的彈窗組件,在popup下右擊新建 Component 并命名為 popup 后,會生成對應(yīng)的 json wxml wxss js 4個文件,也就是一個自定義組件的組成部分,此時項目結(jié)構(gòu)應(yīng)該如下圖所示:

微信小程序,動畫,彈窗組件

第二步上代碼:

popup.wxml

<view hidden="{{!flag}}" class='container' style=''> <view bindtap='_error' class='wrap {{wrapAnimate}}' style='background:rgba(0,0,0,{{bgOpacity}});'></view> <view class='popup-container {{popupAnimate}}'> <view class="wx-popup-title">{{title}}</view> <view class="wx-popup-con">{{content}}</view> <view class="wx-popup-btn">  <text class="btn-no" bindtap='_error'>{{btn_no}}</text>  <text class="btn-ok" bindtap='_success'>{{btn_ok}}</text> </view> <image bindtap='_error' src='../../image/close.png' mode='widthFix' class='btn-colse'></image> </view></view>

popup.wxss

.container{font-size:15px;color:#666;font-weight: bold;z-index:2;position:fixed;width:100vw;height:100vh;}.wrap{position:fixed;top:0;left:0;bottom:0;right:0;}.popup-container {position: fixed;left: 50%;top: 100%;width: 80%;max-width: 600rpx;border: 2rpx solid #ccc;border-radius: 10rpx;box-sizing: bordre-box;transform: translate(-50%, -50%);background: #fff;opacity: 0;}.wx-popup-title {width: 100%;padding: 20rpx 0;text-align: center;font-size: 40rpx;border-bottom: 2rpx solid #89cfea;}.wx-popup-con {margin: 60rpx 10rpx;text-align: center;}.wx-popup-btn {display: flex;justify-content: space-around;margin-bottom: 40rpx;}.wx-popup-btn text {display: flex;align-items: center;justify-content: center;width: 30%;height: 88rpx;border: 2rpx solid #ccc;border-radius: 88rpx;}.btn-colse{width:35px;height:35px;position:absolute;bottom:-60px;left:50%;margin-left:-17.5px;}.wrapAnimate{animation: wrapAnimate 1s linear forwards}@keyframes wrapAnimate{ 0%{} 100%{background:rgba(0,0,0,0.7);}}.wrapAnimateOut{animation: wrapAnimateOut 1s 0.2s linear forwards}@keyframes wrapAnimateOut{ 0%{background:rgba(0,0,0,0.7);} 100%{background:rgba(0,0,0,0);}}.popupAnimate{animation: popupAnimate 1.2s linear forwards}@keyframes popupAnimate{ 0%{} 60%{top:47%;opacity: 1;} 80%{top:53%;opacity: 1;} 100%{top:50%;opacity: 1;}}.popupAnimateOut{animation: popupAnimateOut 1.2s linear forwards}@keyframes popupAnimateOut{ 0%{top:50%;opacity: 1;} 20%{top:47%;opacity: 1;} 100%{}}

popup.js

Component({ options: { multipleSlots: true // 在組件定義時的選項中啟用多slot支持 }, /*組件的屬性列表*/ properties: { title: {  type: String,  value: '標題' }, // 彈窗內(nèi)容 content: {  type: String,  value: '內(nèi)容' }, // 彈窗取消按鈕文字 btn_no: {  type: String,  value: '取消' }, // 彈窗確認按鈕文字 btn_ok: {  type: String,  value: '確定' } }, /* 組件的初始數(shù)據(jù) */ data: { flag: true, bgOpacity:0, wrapAnimate:'wrapAnimate', popupAnimate:'popupAnimate' }, /* 組件的方法列表 */ methods: { //隱藏彈框 hidePopup: function () {  const that = this;  this.setData({ bgOpacity: 0.7, wrapAnimate: "wrapAnimateOut", popupAnimate:"popupAnimateOut"})  setTimeout(function(){  that.setData({flag: false})  },1200) }, /* 內(nèi)部私有方法建議以下劃線開頭 triggerEvent 用于觸發(fā)事件 */ _error() {//觸發(fā)取消回調(diào)  this.triggerEvent("error") }, _success() {//觸發(fā)成功回調(diào)  this.triggerEvent("success"); } }})

popup.json

{ "component": true, "usingComponents": {}}

第三步引用組件:

index.json

{ "usingComponents": { "popup":"/components/popup/popup" }}

index.wxml

<popup id='popup' content='學(xué)會了嗎' btn_no='沒有' btn_ok='學(xué)會了' binderror="_error" bindsuccess="_success" ></popup>

index.js

Page({ showPopup() { this.popup.showPopup(); }, //取消事件 _error() { console.log('你點擊了取消'); this.selectComponent("#popup").hidePopup(); }, //確認事件 _success() { console.log('你點擊了確定'); this.selectComponent("#popup").hidePopup(); }})

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 亚洲视频成人在线 | 久久久综合 | 欧美一级黄色录相 | 九色在线78m | 中国洗澡偷拍在线播放 | cosplay裸体福利写真 | 大学生一级毛片在线视频 | 日日天日日夜日日摸 | 一区二区精品视频 | 亚洲欧美不卡视频 | 午夜精品久久久久久毛片 | 日韩毛片在线看 | 亚洲成人入口 | 综合国产一区 | 亚洲第一激情网 | 精品一区二区6 | 日韩欧美中文字幕视频 | 欧美交在线| 九色中文字幕 | 日本黄色a视频 | 日韩黄色免费电影 | 免费观看黄色一级视频 | 成人做爰s片免费看网站 | 欧美性生活免费视频 | 欧美精品18 | 成人三级黄色片 | av在线一区二区三区四区 | 日韩蜜桃视频 | 色屁屁xxxxⅹ在线视频 | 国产精品视频成人 | 精品国产一区在线 | 欧美精品一区二区三区四区 | 91久久国产露脸精品国产护士 | 日韩理论电影网 | 久久伊人国产精品 | 欧美一级做一级爱a做片性 91在线视频观看 | 精精国产xxxx视频在线野外 | 亚洲综合精品成人 | 久久精品欧美一区二区 | 日韩av电影免费看 | 欧美日本亚洲视频 |