当前位置:   article > 正文

微信小程序动画实现弹出(关闭)优惠卷页面_微信小程序优惠券弹出窗怎么做

微信小程序优惠券弹出窗怎么做

进入页面是动态弹出优惠卷,点击关闭再次运行代码即可弹出,其中图片可根据个人需要更换:

代码如下:

wxml

  1. <view>
  2. <!-- 弹窗遮罩层 -->
  3. <view wx:if="{{show}}" class="popover-mask-layer"></view>
  4. <view hidden="{{!show}}" class="container" animation="{{cartoonData}}">
  5. <image bindload="cartoon" class="logo" mode="widthFix" src="../../icon/logo.jpeg"></image>
  6. <view class="content">
  7. <view class="font">新人专享优惠</view>
  8. <view class="middle">
  9. <view class="text">送你新人见面礼</view>
  10. <view class="ticket">
  11. <view class="left">
  12. <view class="money">¥20</view>
  13. <view class="liter">首杯立减</view>
  14. </view>
  15. <view class="right">
  16. <view class="logo">
  17. <image mode="widthFix" src="../../icon/search.png"></image>
  18. </view>
  19. </view>
  20. </view>
  21. </view>
  22. <view class="foot">
  23. <view class="title">第一杯咖啡 喝椰树</view>
  24. <view>
  25. <button class="button">立即使用</button>
  26. </view>
  27. </view>
  28. </view>
  29. <view class="bottom" bindtap="closeTheCouponPopUp">
  30. <image mode="widthFix" src="{{closeBtnImages}}"></image>
  31. </view>
  32. </view>
  33. </view>

css:

  1. .usermotto{
  2. margin-top: 100px;
  3. border:solid;
  4. }
  5. .container{
  6. transform: scale(0);
  7. }
  8. .content{
  9. width: 400rpx;
  10. height: 500rpx;
  11. display: flex;
  12. flex-direction: column;
  13. align-items: center;
  14. background-color: orangered;
  15. border-radius: 10px 10px 10px 10px;
  16. /* z-index: 1000; */
  17. }
  18. .font{
  19. color: white;
  20. background-color: #FF4500;
  21. width: 220rpx;
  22. text-align: center;
  23. height: 50rpx;
  24. border-radius: 0 0 12px 12px;
  25. z-index: 999;
  26. font-size: 17px;
  27. font-weight: bold;
  28. }
  29. .middle{
  30. margin-top: -46rpx;
  31. width: 100%;
  32. height: 250rpx;
  33. background-color: #FFFFF0;
  34. display: flex;
  35. flex-direction: column;
  36. border-radius: 10px 10px 0 0;
  37. /* justify-content: center; */
  38. align-items: center;
  39. }
  40. .text{
  41. color: orangered;
  42. font-weight: bolder;
  43. letter-spacing: 1px;
  44. margin-top: 50rpx;
  45. font-size: 17px;
  46. }
  47. .ticket{
  48. width: 80%;
  49. height: 140rpx;
  50. /* background-color: #FF9933; */
  51. background-color: white;
  52. border-radius: 5px;
  53. display: flex;
  54. flex-direction: row;
  55. margin-top: 20rpx;
  56. }
  57. .left{
  58. flex: 3;
  59. color: #D2691E;
  60. background-color: #FFDEAD;
  61. border-radius: 5px;
  62. background:radial-gradient(circle at right 0, transparent 16rpx, #FFDEAD 0) left 0 /100% 50% no-repeat,
  63. radial-gradient(circle at right 100%, transparent 16rpx, #FFDEAD 0) left 100% /100% 50% no-repeat;
  64. display: flex;
  65. flex-direction: column;
  66. justify-content: center;
  67. align-items: center;
  68. }
  69. .right{
  70. flex: 2;
  71. background-color: #FFDEAD;
  72. border-radius: 10px;
  73. text-align: center;
  74. background:radial-gradient(circle at left 0, transparent 16rpx, #FFDEAD 0) left 0 /100% 50% no-repeat,
  75. radial-gradient(circle at left 100%, transparent 16rpx, #FFDEAD 0) left 100% /100% 50% no-repeat;
  76. display: flex;
  77. justify-content: center;
  78. align-items: flex-end;
  79. height: 100%;
  80. }
  81. .foot{
  82. width: 100%;
  83. height: 250rpx;
  84. border-radius: 0 0 10px 10px;
  85. background-color: teal;
  86. background: radial-gradient(200px 50px at 110px 0, #FFFFF0 60%, orangered 65%);
  87. }
  88. .title{
  89. margin-top: 90rpx;
  90. text-align: center;
  91. font-weight: bold;
  92. color: white;
  93. letter-spacing: 1px;
  94. font-size: 13px;
  95. font-family:"宋体",Times,serif;
  96. }
  97. .button{
  98. border-radius: 20px;
  99. margin-top: 20rpx;
  100. color: #D2691E;
  101. background-color: #F4A460;
  102. /* height: 60rpx; */
  103. font-size: 17px;
  104. font-weight: bolder;
  105. }
  106. .liter{
  107. font-weight: bolder;
  108. letter-spacing: 1px;
  109. font-size: 10px;
  110. /* font-family:"黑体",Times,serif; */
  111. }
  112. .money{
  113. font-size: 28px;
  114. font-weight: bolder;
  115. }
  116. .logo{
  117. border-radius: 50px;
  118. width: 100rpx;
  119. }
  120. .popover-mask-layer {
  121. height: 100vh;
  122. width: 100vw;
  123. background-color: rgba(129, 126, 126, 0.5);
  124. position: fixed;
  125. top: 0;
  126. z-index: 0;
  127. }
  128. .bottom{
  129. width: 40rpx;
  130. height: 40rpx;
  131. border-radius: 10px;
  132. margin-top: 30rpx;
  133. }

js:

  1. Page({
  2. /**
  3. * 页面的初始数据
  4. */
  5. data: {
  6. show:false,
  7. closeBtnImages: 'http://m.qpic.cn/psc?/V14ZaBeY40XWC8/zkoezU7GGNbZGOF.DPhgQZjV2a5npNMM5D47K1jMLBHO3ccXXkEwsTHa*69Gi8pCGkdmz4imEISAR0fRbZj7*malDMMANN7ZzH8oI6XDWDk!/b&bo=QABAAEAAQAADCSw!&rf=viewer_4'
  8. },
  9. cartoon:function(){
  10. // var that = this;
  11. setTimeout(()=>{
  12. this.setData({
  13. show:true
  14. })
  15. var animation=wx.createAnimation({
  16. duration:600,
  17. timingFunction:'ease-in-out'
  18. });
  19. // that.animation = animation;
  20. animation.scale(1).step();
  21. this.setData({
  22. cartoonData:animation.export()
  23. })
  24. },500)
  25. },
  26. closeTheCouponPopUp:function(){
  27. var animation=wx.createAnimation({
  28. duration:600,
  29. timingFunction:'ease-in-out'
  30. });
  31. animation.scale(0).opacity(0).step();
  32. this.setData({
  33. cartoonData:animation.export(),
  34. })
  35. setTimeout(()=>{
  36. this.setData({
  37. show:false
  38. })
  39. },1000)
  40. },
  41. /**
  42. * 生命周期函数--监听页面加载
  43. */
  44. onLoad(options) {
  45. },
  46. /**
  47. * 生命周期函数--监听页面初次渲染完成
  48. */
  49. onReady() {
  50. },
  51. /**
  52. * 生命周期函数--监听页面显示
  53. */
  54. onShow() {
  55. },
  56. /**
  57. * 生命周期函数--监听页面隐藏
  58. */
  59. onHide() {
  60. },
  61. /**
  62. * 生命周期函数--监听页面卸载
  63. */
  64. onUnload() {
  65. },
  66. /**
  67. * 页面相关事件处理函数--监听用户下拉动作
  68. */
  69. onPullDownRefresh() {
  70. },
  71. /**
  72. * 页面上拉触底事件的处理函数
  73. */
  74. onReachBottom() {
  75. },
  76. /**
  77. * 用户点击右上角分享
  78. */
  79. onShareAppMessage() {
  80. }
  81. })

参考:https://blog.csdn.net/weixin_42063951/article/details/104062033

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/284045
推荐阅读
相关标签
  

闽ICP备14008679号