首页 > 其他分享 >uni-app 弹出层组件的实现

uni-app 弹出层组件的实现

时间:2023-04-07 15:26:26浏览次数:35  
标签:bottom 100% top 弹出 fadein 组件 uni app

uni-app 弹出层组件的实现

以下是一个简单的 uni-app 弹出层组件的实现代码示例,它可以根据传递的属性来控制弹出层的显示和隐藏:

<template>
  <view
    class="overlay "
    v-show="visible"
    @click="close"
    :class="{
			'center' : position==='center' ,
			'bottom' : position==='bottom',
			'top' : position==='top',
			}"
  >
    <view
      class="modal"
      @click.stop
      :class="{
			'bottom-modal' : position==='bottom',
			'bottom-modal-fadein': position==='bottom',
			'top-modal' : position==='top',
			'top-modal-fadein': position==='top',
			}"
    >
      <slot></slot>
    </view>
  </view>
</template>

<script>
  export default {
    name: "popup",
    props: {
      visible: {
        type: Boolean,
        default: false,
      },
      position: {
        type: String,
        default: "bottom",
      },
    },
    methods: {
      close() {
        this.$emit("update:visible", false);
      },
    },
  };
</script>

<style scoped>
  .overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 999;
    display: flex;
  }

  .center {
    justify-content: center;
    align-items: center;
  }

  .modal {
    background-color: #fff;
    padding: 20px;
    border-radius: 10px;
  }

  .bottom {
    justify-content: center;
    align-items: flex-end;
  }

  .bottom-modal {
    bottom: 0;
    width: 100%;
    min-height: 100px;
    border-radius: 10px 10px 0 0;
  }

  .bottom-modal-fadein {
    animation: bottom-top-fadein 500ms linear;
  }

  /* 自下到上淡入 */
  @keyframes bottom-top-fadein {
    0% {
      transform: translate(0, 100%);
    }

    100% {
      transform: none;
    }
  }

  .top {
    justify-content: center;
    align-items: flex-start;
  }

  .top-modal {
    top: 0;
    width: 100%;
    min-height: 100px;
    border-radius: 0 0 10px 10px;
  }

  .top-modal-fadein {
    animation: top-bottom-fadein 500ms linear;
  }

  /* 自上到下淡入 */
  @keyframes top-bottom-fadein {
    0% {
      transform: translate(0, -100%);
    }

    100% {
      transform: none;
    }
  }
</style>

在使用此组件时,可以通过传递“visible”属性来控制弹出层的显示和隐藏。可以在组件的插槽中添加内容。例如,以下代码将创建一个弹出层,当按钮被点击时显示:

<template>
  <view>
    <button @click="showModal">Show Modal</button>
    <popup
      :visible="modalVisible"
      position="bottom"
      @update:visible="modalVisible = $event"
    >
      <h2>Modal Title</h2>
      <p>Modal content goes here...</p>
      <button @click="modalVisible = false">Close</button>
    </popup>
  </view>
</template>

<script>
  // 在根目录下的 components 文件夹添加的组件无需导入

  export default {
    data() {
      return {
        modalVisible: false,
      };
    },
    methods: {
      showModal() {
        this.modalVisible = true;
      },
    },
  };
</script>

标签:bottom,100%,top,弹出,fadein,组件,uni,app
From: https://www.cnblogs.com/yuzhihui/p/17295723.html

相关文章

  • uni-app 日历组件的实现
    uni-app日历组件的实现以下是一个基于uni-app的简单日历组件实现代码,包括了日历的基本布局和日期选择功能:<template><viewclass="calendar"><viewclass="calendar-header"><viewclass="calendar-prev"@click="prevMonth">上个月......
  • Approval action add link to model driven record
    Whenyouaredecidingifyouwanttoapproveanaction,youprobablywantmoreinformationthenadescription.LuckilywecanaddalinktoourApprovalrequest!Thisisafollowuponmy previouspost whereIshowedhowtotriggeranApprovalinsideaBu......
  • 火山引擎数智平台拆解 APP改版场景中蕴含的数据思维
    更多技术交流、求职机会,欢迎关注字节跳动数据平台微信公众号,回复【1】进入官方交流群 你有没有遇到过,打开一款经常使用的APP,它却跳出一条需要你升级版本的提示? 大多数情况下,用户可能会直接点击「现在升级」或「稍后提醒我」,如果选择了后者,那接下来每一次使用APP,用户就会......
  • 火山引擎数智平台拆解 APP改版场景中蕴含的数据思维
     更多技术交流、求职机会,欢迎关注字节跳动数据平台微信公众号,回复【1】进入官方交流群你有没有遇到过,打开一款经常使用的APP,它却跳出一条需要你升级版本的提示?大多数情况下,用户可能会直接点击「现在升级」或「稍后提醒我」,如果选择了后者,那接下来每一次使用APP,用户就会再次收到......
  • 待办事项APP选择哪个
    对于很多网友来说,自己每天需要完成的事情不仅非常多,而且很杂乱,无论是生活中还是工作上的任务都需要按时完成。但是自己的记忆力是非常有限的,所以就会经常忘记待办的任务,对今天需要完成的事项不够清晰明确,无法很好的处理每项任务的优先级,这应该怎么办呢?  其实使用一款好用......
  • 直播app开发,使用koa和MongoDB实现分页和模糊查询
    直播app开发,使用koa和MongoDB实现分页和模糊查询1.分页per_page:一页多少条数据page:第几页 //index.jsconstKoa=require('koa')constapp=newKoa()constRouter=require('koa-router')constusersRouter=newRouter({prefix:'/users'})//MongoDB数据库Us......
  • AppleScript key code
    https://eastmanreference.com/complete-list-of-applescript-key-codestellapplication"SystemEvents"keycode49endtellPlay:tellapplication"iTunes"toplayPause:tellapplication"iTunes"topause......
  • SpringBoot @SpringBootApplication(exclude={DataSourceAutoConfiguration.calss})注
    @SpringBootApplication(exclude={DataSourceAutoConfiguration.calss})该注解的作用是,排除自动注入数据源的配置,用exclude属性进行排除指定的类,在springBoot中使用多数据源时,加上@SpringBootApplication(exclude={DataSourceAutoConfiguration.calss})DataSourceAutoConfigur......
  • uniapp引入阿里巴巴矢量图标
    1、先去图标库下载图标 2.解压下载的文件进入  、 3、输入npminstall-giconfont-tools,再输入iconfont-tools最后无脑回车  4.文件夹会多一个iconfont-weapp的文件夹  5.iconfont-weapp-icon.css放入项目随机位子    6.在App.vue文件夹中,引......
  • UVA - 116 Unidirectional TSP 多段图的最短路
    题目大意:给出一个矩阵,要求每列都要路过,起点必须是第一列,求经过的最短路径的上面的数字和最小解题思路:公式为d[i][j]=min(d[i][j+1],d[i+1][j+1],d[i-1][j+1])+a[i][j],本题要注意,因为可以从最上面一行到最后一行,或者从最后一行到第一行,注意i的变化#include<cstdio>#include<alg......