1. <view class="zan-dialog {{ showDialog ? 'zan-dialog--show' : '' }}">
    2. <!-- 如果想点击弹窗外不隐藏,取消bindtap点击事件即可 -->
    3. <view class="zan-dialog__mask" bindtap="toggleDialog" />
    4. <view class="zan-dialog__container">
    5. <view style='padding:100rpx;'>此处是填充的布局代码</view>
    6. </view>
    7. </view>
    1. .zan-dialog__mask {
    2. position: fixed;
    3. top: 0;
    4. left: 0;
    5. right: 0;
    6. bottom: 0;
    7. z-index: 10;
    8. background: rgba(0, 0, 0, 0); /*设置阴影半透明背景如: background: rgba(0, 0, 0, 0.4);*/
    9. display: none;
    10. }
    11. .zan-dialog__container {
    12. position: fixed;
    13. bottom: 400rpx;
    14. width: 650rpx; /*弹窗布局宽*/
    15. height: 350rpx; /*弹窗布局高,与下面弹出距离transform有关*/
    16. margin-left: 50rpx;
    17. background: #f8f8f8;
    18. transform: translateY(300%); /*弹框弹出距离,与弹框布局高度有关,如300%表示弹起距离为3倍弹窗高度 */
    19. transition: all 0.4s ease;
    20. z-index: 12;
    21. border-radius: 20rpx;
    22. box-shadow: 0px 3px 3px 2px gainsboro; /*弹框的悬浮阴影效果,如不需要可注释该行*/
    23. }
    24. .zan-dialog--show .zan-dialog__container {
    25. transform: translateY(0);
    26. }
    27. .zan-dialog--show .zan-dialog__mask {
    28. display: block;
    29. }
    1. Page({
    2. data: {
    3. showDialog: false
    4. },
    5. /**
    6. * 控制 pop 的打开关闭
    7. * 该方法作用有2:
    8. * 1:点击弹窗以外的位置可消失弹窗
    9. * 2:用到弹出或者关闭弹窗的业务逻辑时都可调用
    10. */
    11. toggleDialog() {
    12. this.setData({
    13. showDialog: !this.data.showDialog
    14. });
    15. },