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 分钟前
判断当前是否为钉钉环境
开发语言·前端·javascript·钉钉·企业应用开发
军军君0126 分钟前
基于Springboot+UniApp+Ai实现模拟面试小工具二:后端项目搭建
前端·javascript·spring boot·spring·微信小程序·前端框架·集成学习
quweiie1 小时前
tp8.0\jwt接口安全验证
前端·安全·jwt·thinkphp
xiaoyan20151 小时前
最新Flutter3.32+Dart3仿微信App聊天实例
前端·flutter·dart
汪敏wangmin2 小时前
Fiddler-抓包后直接生成Loadrunner脚本或者Jmeter脚本
前端·jmeter·fiddler
彤银浦2 小时前
Web学习笔记3
前端·笔记·学习·html5
江城开朗的豌豆2 小时前
退出登录后头像还在?这个缓存问题坑过多少前端!
前端·javascript·vue.js
江城开朗的豌豆3 小时前
Vue的'读心术':它怎么知道数据偷偷变了?
前端·javascript·vue.js
江城开朗的豌豆3 小时前
手把手教你造一个自己的v-model:原来双向绑定这么简单!
前端·javascript·vue.js
我在北京coding3 小时前
el-tree 懒加载 loadNode
前端·vue.js·elementui