帝王谷资源网 Design By www.wdxyy.com
本文实例为大家分享了微信小程序带动画弹窗的具体代码,供大家参考,具体内容如下
基本效果如下:
具体实现如下:
第一步:
新建一个 components 文件夹,用于存放我们以后开发中的所用组件,在 components 组件中新建一个popup文件夹来存放我们的弹窗组件,在popup下右击新建 Component 并命名为 popup 后,会生成对应的 json wxml wxss js 4个文件,也就是一个自定义组件的组成部分,此时项目结构应该如下图所示:
第二步上代码:
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: '标题' }, // 弹窗内容 content: { type: String, value: '内容' }, // 弹窗取消按钮文字 btn_no: { type: String, value: '取消' }, // 弹窗确认按钮文字 btn_ok: { type: String, value: '确定' } }, /* 组件的初始数据 */ 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) }, /* 内部私有方法建议以下划线开头 triggerEvent 用于触发事件 */ _error() {//触发取消回调 this.triggerEvent("error") }, _success() {//触发成功回调 this.triggerEvent("success"); } } })
popup.json
{ "component": true, "usingComponents": {} }
第三步引用组件:
index.json
{ "usingComponents": { "popup":"/components/popup/popup" } }
index.wxml
<popup id='popup' title='弹窗组件' content='学会了吗' btn_no='没有' btn_ok='学会了' 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(); } })
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
标签:
微信小程序,弹窗
帝王谷资源网 Design By www.wdxyy.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
帝王谷资源网 Design By www.wdxyy.com
暂无评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
2024年10月26日
2024年10月26日
- 群星2013-青春缤纷辑压箱宝大公开3CD2[新加坡限量版][WAV整轨]
- 林育群.2013-BalladShow(日本版)【环球】【WAV+CUE】
- 陈加洛.1992-痛到感觉不到【宝丽金】【WAV+CUE】
- 群星.2023-宿命之敌电视剧原声带【韶愔音乐】【FLAC分轨】
- 東京事変-大発見[FLAC+CUE]
- 椎名林檎-三文ゴシップ[FLAC+CUE]
- 2024年08月04日
- 裘德《裘德「最后的水族馆」演唱会LIVE》[320K/MP3][228.89MB]
- 裘德《裘德「最后的水族馆」演唱会LIVE》[24bit 48kHz][FLAC/分轨][2.08G]
- 基因三重奏《如果你什么都不说 音乐会现场录音》[320K/MP3][145.37MB]
- 孟庭苇.1996-月亮说话(2020环球24KGOLD限量版)【上华】【WAV+CUE】
- 群星.1997-新艺宝优质音响系列·国语精选监听版【新艺宝】【WAV+CUE】
- 阿桑.2005-寂寞在唱歌(星外星引进版)【华研国际】【WAV+CUE】
- 基因三重奏《如果你什么都不说 音乐会现场录音》[FLAC/分轨][287.43MB]
- 蔡题谦《我爱你,却依然要看你走》[320K/MP3][88.65MB]