当前位置: 首页 > article >正文

原生实现底部弹窗效果 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>


http://www.kler.cn/a/144795.html

相关文章:

  • system.setProperty导致的https血案
  • 人工智能学习1
  • 【数据结构】时间和空间复杂度
  • Linux系统常用指令大全(图文详解)
  • idea开发jface、swt环境搭建
  • 井盖位移传感器怎么监测井盖安全
  • SELinux零知识学习二十九、SELinux策略语言之类型强制(14)
  • 11 月 25 日 ROS 学习笔记——3D 建模与仿真
  • 等待多个请求(请求并发执行)都完成后结束Loading框
  • 前端路由hash和history的六大区别
  • 【LeetCode】挑战100天 Day15(热题+面试经典150题)
  • c++11新特性篇-可调用对象包装器, 绑定器
  • Python基础教程: sorted 函数
  • 河南省第五届“金盾信安杯”网络与数据安全大赛实操技能赛 部分wp(自己的一些思路和解析 )(主misc crypto )
  • 快手AI布局:从直播电商到大模型,如何打造智能生态?
  • C# 关于异常处理 try-catch语句的使用
  • 【Docker】从零开始:10.registry搭建私有仓库
  • 使用Ruby过滤目录容量大小
  • 在 STM32 上实现温度补偿和校正
  • 计算机视觉面试题-01