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>
相关推荐
Lank_M8 小时前
白底都占八成,PNG 为何只在图表页赢过 JPG
前端
张一凡938 小时前
给 Coding Agent 加一道"架构闸门":Jin 是如何做到"先审架构、再写代码、不漂移"的
前端·后端·agent
Linye8 小时前
AI 写的 HTML 原型全是空壳?聊聊真实 DOM 交互避坑
前端·人工智能
ZANE9 小时前
纯前端实现的 PDF 与图片互相转换工具技术实现
前端
Swot9 小时前
SvelteKit Remote Functions 使用指南
前端·后端
Cooper259 小时前
三源热榜去重加 AI 摘要:URL 唯一键踩出的三个坑
前端·python
Yk酱228409 小时前
A2UI探索随笔-技术选型
前端
前端繁华如梦9 小时前
# 从 73000 行压缩代码到 TypeScript 模块化:我把一个 Three.js FPS 游戏 1:1 复刻了一遍
前端
Penge6669 小时前
React Context 详解:从 Props 传递到跨组件状态共享
前端
Penge66610 小时前
React 事件处理:bind(this) 原理与实际开发常用写法
前端