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>
相关推荐
16年上任的CTO5 分钟前
一文大白话讲清楚webpack进阶——9——ModuleFederation实战
前端·webpack·node.js·模块联邦·federation
子非鱼92111 分钟前
手写instanceof、手写new操作符
开发语言·javascript·原型模式
云博客-资源宝1 小时前
2025最新源支付V7全套开源版+Mac云端+五合一云端
前端
Y编程小白4 小时前
解决运行npm时报错
开发语言·前端·npm
WebGISer_白茶乌龙桃4 小时前
Cesium ArcGisMapServerImageryProvider API 介绍
开发语言·javascript·ecmascript
孙尚香蕉4 小时前
服务器上安装Nginx详细步骤
java·服务器·前端
GISer_Jing5 小时前
前端面试&笔试题目(一)
前端·javascript·vue.js·react.js
赵健zj5 小时前
常见端口的攻击思路
前端
WebGISer_白茶乌龙桃6 小时前
浏览器同源策略:从“源”到安全限制的全面解析
前端·javascript·vue.js·安全
李游Leo7 小时前
JavaScript原型链与继承:优化与扩展的深度探索
开发语言·javascript·原型模式