uni-app:实现右侧弹窗

效果:

代码:

html 复制代码
<template>
  <view class="container">
    <button @click="showModal = true">点击按钮</button>
    <view class="modal-overlay" v-if="showModal" @click="closeModal"></view>
    <view class="modal-container" :class="{ active: showModal }">
      <!-- 右侧弹窗的内容 -->
      <view class="modal-content">
        <!-- 内容区域 -->
        <text>这是右侧弹窗的内容</text>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      showModal: false, // 控制弹窗显示与隐藏
    };
  },
  methods: {
    closeModal() {
      this.showModal = false;
    },
  },
};
</script>

<style>
.container {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 999;
}

.modal-container {
  position: fixed;
  top: 0;
  right: -100%; /* 初始时隐藏弹窗 */
  width: 300px;
  height: 100%;
  background-color: #fff;
  z-index: 1000;
  transition: right 0.3s ease;
}

.modal-container.active {
  right: 0; /* 显示弹窗 */
}

.modal-content {
  padding: 20px;
}
</style>
相关推荐
我的div丢了肿么办4 分钟前
element-plus表格使用:filter-method过滤导致出现无数据
前端·javascript·vue.js
F_Quant5 分钟前
高股息+破净+PEG三因子:年化20%的背后,是一个“敢于证伪自己”的捡烟蒂策略
前端
不可能片场15 分钟前
Electron 发布核验 别把没查到当成没发出去
前端·electron
开开心心就好28 分钟前
文件被占用删不掉?解锁工具强制删除
java·运维·服务器·开发语言·前端·pdf·ocr
inksci1 小时前
发布Ai生成的html markdown 推荐
前端·javascript·html
在西安放羊的牛油果1 小时前
WebP 图片优化方案详解
运维·前端·架构
coding漫漫长路1 小时前
签名PDF一压就失效,接压缩需求前先查这5件事
前端
Lank_M1 小时前
PDF签完名还能改什么?会签能过,压缩不行
前端
补码缩写1 小时前
压缩前查PDF签名,字节搜索会漏掉对象流
前端