uniapp left right 的左右模态框

标题

这是组件

javascript 复制代码
<template>
    <div class="content-wrapper">
      <div
        v-for="(vla, i) in products"
        :key="i"
        :class="['content-page', getPageClass(i)]"
      >
        <slot :data="vla">
          <!-- 用户自定义的内容 -->
        </slot>
      </div>
    </div>
  </template>
  
  <script>
  export default {
    props: {
      products: {
        type: Array,
        required: true
      },
      selectedIndex: {
        type: Number,
        default: 0
      }
    },
    methods: {
      getPageClass(index) {
        if (index === this.selectedIndex) {
          return 'active';
        } else if (index < this.selectedIndex) {
          return 'left';
        } else {
          return 'right';
        }
      }
    }
  };
  </script>
  
  <style scoped>
  .content-wrapper {
    position: relative;
    overflow: hidden;
    height: 300px; /* 根据需要调整高度 */
  }
  
  .content-page {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    transition: all 0.3s ease;
    opacity: 0;
    transform: translateX(100%);
    display: flex;
  }
  
  .content-page.active {
    opacity: 1;
    transform: translateX(0);
  }
  
  .content-page.left {
    transform: translateX(-100%);
  }
  
  .content-page.right {
    transform: translateX(100%);
  }
  </style>

demo 组件调用模拟

javascript 复制代码
<template>
    <div>
      <ProductSlider :products="products" :selectedIndex="selectedIndex">
        <template v-slot:default="{ data }">
          <div class="product-item">
            <h3>{{ data.name }}</h3>
            <p>{{ data.description }}</p>
          </div>
        </template>
      </ProductSlider>
      <button @click="prev">Previous</button>
      <button @click="next">Next</button>
    </div>
  </template>
  
  <script>
  import ProductSlider from './components/content-wrapper.vue'; // 假设组件名为 ProductSlider
  
  export default {
    components: {
      ProductSlider
    },
    data() {
      return {
        products: [
          { name: 'Product 1', description: 'Description 1' },
          { name: 'Product 2', description: 'Description 2' },
          { name: 'Product 3', description: 'Description 3' }
        ],
        selectedIndex: 0
      };
    },
    methods: {
      prev() {
        if (this.selectedIndex > 0) {
          this.selectedIndex--;
        }
      },
      next() {
        if (this.selectedIndex < this.products.length - 1) {
          this.selectedIndex++;
        }
      }
    }
  };
  </script>
  
  <style scoped>
  .product-item {
    padding: 20px;
    background: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 4px;
  }
  </style>
相关推荐
程序员大澈8 分钟前
4个 Vue 路由实现的过程
javascript·vue.js·uni-app
几度泥的菜花10 分钟前
如何禁用移动端页面的多点触控和手势缩放
前端·javascript
狼性书生12 分钟前
electron + vue3 + vite 渲染进程到主进程的双向通信
前端·javascript·electron
肥肠可耐的西西公主20 分钟前
前端(AJAX)学习笔记(CLASS 4):进阶
前端·笔记·学习
拉不动的猪32 分钟前
Node.js(Express)
前端·javascript·面试
Re.不晚38 分钟前
Web前端开发——HTML基础下
前端·javascript·html
几何心凉40 分钟前
如何处理前端表单验证,确保用户输入合法?
前端·css·前端框架
vjmap42 分钟前
如何免费使用AI编程工具(如Trae或Cursor)生成CAD图纸?
javascript
浪遏1 小时前
面试官😏: 讲一下事件循环 ,顺便做道题🤪
前端·面试
Joeysoda1 小时前
JavaEE进阶(2) Spring Web MVC: Session 和 Cookie
java·前端·网络·spring·java-ee