原生实现底部弹窗效果 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>
相关推荐
阿里花盘5 小时前
线上门店经营方案:连锁美容院线上小程序店铺怎么做?
小程序
计算机徐师兄6 小时前
Java基于SpringBoot的足球队管理平台小程序【附源码、文档说明】
微信小程序·小程序·足球队管理平台小程序·java足球队管理平台小程序·足球队管理微信小程序·足球队管理平台·jav足球队管理小程序
千寻技术帮9 小时前
50040_基于微信小程序的项目管理系统
小程序·源码·讲解·文档·ppt
2501_9159090611 小时前
iOS APP 抓包全流程解析,HTTPS 调试、网络协议分析与多工具组合方案
android·ios·小程序·https·uni-app·iphone·webview
2501_9151063212 小时前
游戏上架 App Store 的技术流程解析 从构建到审核的全流程指南
游戏·macos·ios·小程序·uni-app·cocoa·iphone
harrain12 小时前
vue2开发环境搭建指南
vue
一 乐16 小时前
健身达人小程序|基于java+vue健身达人小程序的系统设计与实现(源码+数据库+文档)
java·前端·数据库·vue.js·spring boot·小程序
2501_916007471 天前
iOS 压力测试的工程化体系,构建高强度、多维度、跨工具协同的真实负载测试流程
android·ios·小程序·uni-app·cocoa·压力测试·iphone
小小王app小程序开发1 天前
盲盒抽赏小程序拓展分析:6 大具体玩法设计,破解同质化困局
小程序
说私域1 天前
智能名片链动2+1模式S2B2C商城小程序:构建私域生态“留”量时代的新引擎
大数据·人工智能·小程序