vue实现无缝向上轮播列表

15 篇文章 0 订阅

<template>

  <div class="left-box">

    <el-row :gutter="24" class="right-header right-row">

      <el-col :span="8">批次</el-col>

      <el-col :span="6">时间</el-col>

      <el-col :span="5">标段</el-col>

      <el-col :span="5">人员</el-col>

    </el-row>

    <div id="publishMain" class="main">

      <div id="publishMain1">

        <el-row

          :gutter="24"

          v-for="(item, index) in persons"

          :key="index"

          class="right-values right-row"

          :class="item.class"

        >

          <el-col :span="8">{{ item.a }}</el-col>

          <el-col :span="6">{{ item.b }}</el-col>

          <el-col :span="5">{{ item.c }}</el-col>

          <el-col :span="5">{{ item.d }}</el-col>

        </el-row>

      </div>

      <div id="publishMain2"></div>

    </div>

  </div>

</template>

 

<script>

export default {

  name: "quaright",

  data() {

    return {

      timer: null,

      persons: [

        {

          a: "112-5565",

          b: "2020-06-08 09:39",

          c: "计划问",

          d: "杨方法"

        },

        {

          a: "112-55dd65",

          b: "2020-06-08 09:31",

          c: "计划",

          d: "杨色"

        },

        {

          a: "f5221-96",

          b: "2020-06-08 08:27",

          c: "合格区",

          d: "胥门"

        },

        {

          a: "112-55d65",

          b: "2020-06-07 16:53",

          c: "计划",

          d: "胥门"

        },

        {

          a: "1w12-5565",

          b: "2020-06-07 16:23",

          c: "很关键",

          d: "何放"

        },

        {

          a: "112-5565e",

          b: "2020-06-07 15:09",

          c: "功夫",

          d: "何胥门"

        },

        {

          a: "112-556d5",

          b: "2020-06-07 14:38",

          c: "大坝",

          d: "胥门"

        },

        {

          a: "112-556543d",

          b: "2020-06-07 13:59",

          c: "大坝",

          d: "胥门"

        }

      ]

    };

  },

  async mounted() {

    this.$nextTick(() => {

      this.rollUp();

    });

  },

  beforeDestroy() {

    this.timer = null;

    clearInterval(this.timer);

  },

  methods: {

    /*向上轮播*/

    async rollUp() {

      let ul1 = document.getElementById("publishMain1");

      let ul2 = document.getElementById("publishMain2");

      let box = document.getElementById("publishMain");

      ul2.innerHTML = ul1.innerHTML;

      box.scrollTop = 0;

      function rollStart() {

        if (box.scrollTop >= ul1.scrollHeight) {

          box.scrollTop = 0;

        } else {

          box.scrollTop++;

        }

      }

      this.timer = setInterval(rollStart, 50);

    }

  }

};

</script>

 

<style lang="scss" scoped>

.left-box {

  width: 100%;

  height: 100%;

  display: flex;

  flex-direction: column;

 

  .right-row {

    margin: 0 !important;

    height: 3rem;

    line-height: 3rem;

    font-size: 1.2rem;

    color: #fff;

    .el-col {

      padding: 0 !important;

      text-align: center;

    }

    .el-col-8 {

      text-align: left;

      text-indent: 1.5rem;

      overflow: hidden;

      white-space: nowrap;

      text-overflow: ellipsis;

    }

  }

  .right-header {

    border-bottom: 0.1rem solid #405fc9;

    line-height: 2.2rem;

  }

 

  .main {

    overflow: hidden;

    height: calc(100% - 3rem);

    .right-values {

      .w-info {

        overflow: hidden;

        text-overflow: ellipsis;

        white-space: nowrap;

      }

    }

  }

}

</style>

 

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue 2 中实现无缝轮播可以通过以下步骤进行: 1. 创建一个 Vue 组件,命名为`Carousel`。 2. 在`Carousel`组件中,定义一个数组来存储需要轮播的图片列表。 3. 在`mounted`生命周期钩子函数中,初始化轮播的一些参数,例如当前显示的图片索引、定时器等。 4. 在模板中,使用`v-for`指令循环渲染图片列表,并设置每个图片项的样式,使其水平排列。 5. 使用`transform: translateX()`样式属性,对轮播项进行水平移动,实现轮播效果。可以通过计算当前索引和图片宽度来设置移动的距离。 6. 添加一个定时器,在一定时间间隔内更新当前显示的图片索引,实现自动轮播效果。 7. 监听鼠标滑入和滑出事件,在鼠标滑入时清除定时器,在鼠标滑出时重新启动定时器,实现鼠标悬停时暂停轮播的效果。 以下是一个简单示例代码: ```html <template> <div class="carousel"> <div class="carousel-wrapper" :style="{ transform: `translateX(${translateX}px)` }"> <div v-for="(item, index) in images" :key="index" class="carousel-item"> <img :src="item" alt="carousel item" /> </div> </div> </div> </template> <script> export default { data() { return { images: [ 'image1.jpg', 'image2.jpg', 'image3.jpg', 'image4.jpg', ], currentIndex: 0, translateX: 0, intervalId: null, }; }, mounted() { this.startCarousel(); }, beforeDestroy() { clearInterval(this.intervalId); }, methods: { startCarousel() { this.intervalId = setInterval(() => { this.nextSlide(); }, 3000); }, nextSlide() { if (this.currentIndex === this.images.length - 1) { this.currentIndex = 0; this.translateX = 0; } else { this.currentIndex++; this.translateX -= this.$refs.carouselItem.offsetWidth; } }, }, }; </script> <style> .carousel { width: 100%; overflow: hidden; } .carousel-wrapper { display: flex; transition: transform 0.5s; } .carousel-item { flex-shrink: 0; } </style> ``` 以上代码是一个简单的示例,实现了简单的无缝轮播效果。你可以根据需求进行进一步的样式和功能定制。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值