原生实现底部弹窗效果 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>
相关推荐
计算机毕设指导64 小时前
基于微信小程序的校园食堂点餐系统【源码文末联系】
java·spring boot·微信小程序·小程序·tomcat·maven·intellij-idea
旧梦星轨5 小时前
掌握 Vite 环境配置:从 .env 文件到运行模式的完整实践
前端·前端框架·node.js·vue·react
项目題供诗5 小时前
微信小程序黑马优购(项目)(八)
微信小程序·小程序
2501_915918415 小时前
iOS 项目中证书管理常见的协作问题
android·ios·小程序·https·uni-app·iphone·webview
2501_915918416 小时前
提升 iOS 应用安全审核通过率的一种思路,把容易被拒的点先处理
android·安全·ios·小程序·uni-app·iphone·webview
sg_knight6 小时前
模块热替换 (HMR):前端开发的“魔法”与提速秘籍
前端·javascript·vue·浏览器·web·模块化·hmr
00后程序员张6 小时前
APP如何快速上架Apple Store:完整上架流程与常见问题解析
android·小程序·https·uni-app·iphone·webview
Chloe.Zz6 小时前
微信小程序接入大模型实战 4:塔罗咨询室(含代码)
语言模型·微信小程序·小程序
2501_916008896 小时前
iOS 应用发布流程中常被忽视的关键环节
android·ios·小程序·https·uni-app·iphone·webview
WX:ywyy67986 小时前
海外短剧APP H5开发全流程:从技术架构到开源交付实战指南
h5·海外短剧·短剧app开发·海外短剧app开发·海外短剧app·海外短剧h5·海外短剧开发