原生实现底部弹窗效果 h5 小程序

 

<template>
  <div class="home">
    <div class="btn" @click="showPopup='show'">
        弹出底部蒙层
    </div>
    <div class="popup " catchtouchmove="true" :class="showPopup" >
        <div class="mask"></div>
        <div class="layer attr-content">
            <div class="close" @click="closePopup">关闭</div>
        </div>
    </div>
  </div>
</template>
<script>
export default{
    data(){
        return{
            showPopup:'none'
        }
    },
    methods:{
        closePopup(){
            this.showPopup = 'hide';
            setTimeout(() => {
                this.showPopup = 'none';
            }, 250);
        }
    }
}
</script>

 

<style lang="scss" scoped>
.btn{
    width:200px;
    height:50px;
    text-align: center;
    line-height: 50px;
    font-size:16px;
    position: fixed;
    left:50%;
    top:40%;
    transform: translateX(-50%);
    cursor: pointer;
}

.popup {
    position: fixed;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 999;
    overflow: hidden;
    &.show {
        display: block; 
    }   
    .close{
        width:100px;
        height:50px;
        font-size: 16px;
        line-height: 50px;
        text-align: center;
    }
    &.hide {
        .mask {
            animation: hidePopup 0.2s linear both;
        }
    
        .layer {
            animation: hideLayer 0.2s linear both;
        }
    }
    
    &.none {
        display: none;
    }
    
    .mask {
        position: fixed;
        top: 0;
        width: 100%;
        height: 100%;
        z-index: 1;
        background-color: rgba(0, 0, 0, 0.3);
        animation: showPopup 0.2s linear both;

    }
    .layer {
        display: flex;
        width: 100%; 
        flex-direction: column;
        min-height: 40vh;
        max-height: 1014rpx;
        position: fixed;
        z-index: 99;
        bottom: 0;
        border-radius: 10upx 10upx 0 0;
        background-color: #fff;
        animation: showLayer 0.2s linear both;
    }
}
@keyframes showPopup {
    0% {
        opacity: 0;
    }

    100% {
        opacity: 1;
    }
}

@keyframes hidePopup {
    0% {
        opacity: 1;
    }

    100% {
        opacity: 0;
    }
}

@keyframes showLayer {
    0% {
        transform: translateY(120%);
    }

    100% {
        transform: translateY(0%);
    }
}

@keyframes hideLayer {
    0% {
        transform: translateY(0);
    } 
    100% {
        transform: translateY(120%);     
    }
}
</style>

  • 13
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

路光.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值