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

html 复制代码
<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>
javascript 复制代码
<script>
export default{
    data(){
        return{
            showPopup:'none'
        }
    },
    methods:{
        closePopup(){
            this.showPopup = 'hide';
            setTimeout(() => {
                this.showPopup = 'none';
            }, 250);
        }
    }
}
</script>
css 复制代码
<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>
相关推荐
努力学习的木子2 小时前
uniapp如何隐藏默认的页面头部导航栏,uniapp开发小程序如何隐藏默认的页面头部导航栏
前端·小程序·uni-app
水星记_5 小时前
echarts-wordcloud:打造个性化词云库
前端·vue
guanpinkeji8 小时前
家政小程序的开发,带动市场快速发展,提高家政服务质量
小程序·小程序开发·家政·家政小程序·家政服务小程序
Cc_Debugger8 小时前
微信小程序消息通知(一次订阅)
微信小程序·小程序
长而不宰9 小时前
关闭vue3中脑瘫的ESLine
vue·intellij-idea
栗豆包14 小时前
【计算机毕业设计】020基于weixin小程序订餐系统
小程序·课程设计
Amd79415 小时前
Nuxt框架中内置组件详解及使用指南(二)
前端·vue·教程·开发·组件·代码·nuxt3
2401_8459364515 小时前
PHP智慧门店微信小程序系统源码
微信·微信小程序·小程序·微信公众平台·微信开放平台
井眼15 小时前
微信小程序-组件样式隔离
微信小程序·小程序
社会底层无业大学生1 天前
uniapp微信小程序电子签名
微信小程序·小程序·uni-app