Vue implements seamless scrolling of lists

Vue implements seamless scrolling of lists

This article example shares the specific code of vue to achieve seamless scrolling of the list for your reference. The specific content is as follows

HTML part code

<template>
  <div id="box" class="wrapper">
    <div class="contain" id="con1" ref="con1" :class="{anim:animate==true}">
      <List
        v-for="(item,index) in cloudList"
        :key="index"
        :listData="item"
        :index="index"
        :date="date"
      ></List>
    </div>
  </div>
</template>

List is a single list component and can also be replaced by li.

CSS part code

<style scoped>
.wrapper {
  width: 96vw;
  height: 90vh;
  position: absolute;
  left: 2vw;
  top: 1rem;
  overflow: hidden;
}
.contain > div:nth-child(2n) { //This style is required for my project and has nothing to do with seamless scrolling. Margin-left: 2vw can be ignored;
}
.anim {
  transition: all 0.5s;
  margin-top: -7vh;
}
</style>

My List component is set to float: left, so the div with id="con1" has no height

js part of the code

<script>
import List from './List';
export default {
  name: 'Contain',
  data () {
    return {
      cloudList: [], //Array used to store list data date: '', //Latest data update date animate: false,
      time: 3000, //Timed scrolling interval setTimeout1: null,
      setInterval1: null
    };
  },
  components:
    List
  },
  methods: {
    // Get json data and update date getCloudListData () {
      const _this = this;
      _this.$api.getCloudListData().then(res => {
        _this.cloudList = res;
      });
      var newDate = new Date();
      _this.date = _this.dateFtt('yyyy-MM-dd hh:mm:ss', newDate);
    },
    // Date format dateFtt (fmt, date) {
      var o = {
        'M+': date.getMonth() + 1, // Month 'd+': date.getDate(), // Day 'h+': date.getHours(), // Hours 'm+': date.getMinutes(), // Minutes 's+': date.getSeconds(), // Seconds 'q+': Math.floor((date.getMonth() + 3) / 3), // Quarter S: date.getMilliseconds() // Milliseconds };
      if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(
          RegExp.$1,
          (date.getFullYear() + '').substr(4 - RegExp.$1.length)
        );
      }
      for (var k in o) {
        if (new RegExp('(' + k + ')').test(fmt)) {
          fmt = fmt.replace(
            RegExp.$1,
            RegExp.$1.length === 1
              ? o[k]
              : ('00' + o[k]).substr(('' + o[k]).length)
          );
        }
      }
      return fmt;
    },
    // Scroll scroll () {
      const _this = this;
      _this.animate = true;
      clearTimeout(_this.setTimeout1);
      _this.setTimeout1 = setTimeout(() => {
        var parent = document.getElementById('con1');
        var first = document.getElementById('con1').children[0];
        var second = document.getElementById('con1').children[1];
        parent.removeChild(first);
        parent.removeChild(second);
        parent.appendChild(first);
        parent.appendChild(second);
        _this.animate = false;
      }, 500);
    }
  },
  created () {
    const _this = this;
    _this.getCloudListData();
    //The timer updates the data every 24 hours setInterval(() => {
      _this.getCloudListData();
    }, 24 * 60 * 60 * 1000);
  },
  mounted () {
    const _this = this;
    var contain = document.getElementById('box');
    _this.setInterval1 = setInterval(_this.scroll, _this.time);
    var setInterval2 = null;
    //Mouse moves into the scrolling area to stop scrolling contain.onmouseenter = function () {
      clearInterval(_this.setInterval1);
      var count = 0;
      // If the mouse does not move for more than ten seconds, start scrolling setInterval2 = setInterval(function () {
        count++;
        if (count === 10) {
          _this.scroll();
          _this.setInterval1 = setInterval(_this.scroll, _this.time);
        }
      }, 1000);
      //Stop scrolling as soon as the mouse moves and set the count to 0
      contain.onmousemove = function () {
        count = 0;
        clearInterval(_this.setInterval1);
      };
    };
    // The mouse moves out of the scrolling area contain.onmouseleave = function () {
      clearInterval(setInterval2);
      clearInterval(_this.setInterval1);
      _this.scroll();
      _this.setInterval1 = setInterval(_this.scroll, _this.time);
    };
  }
};
</script>

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Vue achieves seamless upward scrolling effect of messages
  • Realize seamless scrolling effect based on vue-seamless-scroll
  • Detailed explanation of how to use vue-seamless-scroll seamless scrolling component
  • Vue achieves seamless scrolling of infinite messages
  • Vue implements simple seamless scrolling effect
  • Vue implements seamless scrolling effect of list
  • Vue implements seamless vertical scrolling of lists
  • Vue3 implements CSS infinite seamless scrolling effect
  • Seamless scrolling effect based on vue.js
  • Vue or css animation to achieve seamless scrolling of the list upwards

<<:  How to set PATH environment variable in Linux system (3 methods)

>>:  Kill a bunch of MySQL databases with just a shell script like this (recommended)

Recommend

Detailed example of locating and optimizing slow query sql in MySQL

Table of contents 1. How to locate and optimize s...

How to generate Vue user interface by dragging and dropping

Table of contents Preface 1. Technical Principle ...

JavaScript event loop case study

Event loop in js Because JavaScript is single-thr...

How to hide the version number in Nginx

Nginx hides version number In a production enviro...

Vue easily realizes watermark effect

Preface: Use watermark effect in vue project, you...

Win10 configuration tomcat environment variables tutorial diagram

Before configuration, we need to do the following...

mysql5.7.21.zip installation tutorial

The detailed installation process of mysql5.7.21 ...

Detailed explanation of the pitfalls of mixing MySQL order by and limit

In MySQL, we often use order by for sorting and l...

Seven different color schemes for website design experience

The color matching in website construction is ver...

An example of implementing a simple infinite loop scrolling animation in Vue

This article mainly introduces an example of Vue ...

Linux implements automatic and scheduled backup of MySQL database every day

Overview Backup is the basis of disaster recovery...

The difference between redundant and duplicate indexes in MySQL

MySQL allows you to create multiple indexes on a ...

Paragraph layout and line breaks in HTML web pages

The appearance of a web page depends largely on i...