js realizes the dynamic loading of data by waterfall flow bottoming out

js realizes the dynamic loading of data by waterfall flow bottoming out

This article shares with you the specific code of js to realize the dynamic loading of data when the waterfall flow touches the bottom. For your reference, the specific content is as follows


// onScrollEvent scroll bar event <div class="box" ref="box" @mousewheel="onScrollEvent">
    //The content of each block start
      <div class="boxItemStyle" v-for="(userTag, i) in dataSource" :key="i" ref="boxItemStyle">
        <a-tag class="moreStyle" @click="more(userTag.primaryParam)"> More></a-tag>
        <div v-for="item in userTag.userTag" :key="item.code">
          <p>
            {{ item.name }}:
            {{ item.value }}
          </p>
        </div>
      </div>
      //Contents in each block end
</div>

Waterfall layout

waterFall() {
  // Subtract the width of the margin var pageWidth = this.$refs.box.offsetWidth - 200
      var columns = 4; //Define a row with 4 columns var itemWidth = parseInt(pageWidth / columns);
      var arr = [];
      var nodes = document.getElementsByClassName("boxItemStyle")
      setTimeout(() => {
        //var node1 = Array.from(nodes)
       // var node2 = Array.prototype.slice.call(nodes)
        for (var i = 0; i < nodes.length; i++) {
          nodes[i].style.width = itemWidth + "px"
          if (i < columns) {
            nodes[i].style.width = itemWidth + "px"
            nodes[i].style.left = itemWidth * i + i * 50 + "px"
            nodes[i].style.top = 0
            arr.push(nodes[i].offsetHeight);
          } else {
            // Find the minimum height in the array and its index var minHeight = arr[0];
            var index = 0;
            for (var j = 0; j < arr.length; j++) {
              if (minHeight > arr[j]) {
                minHeight = arr[j];
                index = j;
              }
            }
            nodes[i].style.top = arr[index] + 30 + "px",
              nodes[i].style.left = nodes[index].offsetLeft + 'px';
            // Modify the height of the minimum column // The height of the minimum column = the current height + the height of the spliced ​​column arr[index] = arr[index] + nodes[i].offsetHeight + 30; // Set a distance of 30 }
        }
      }, 1000)
    },

Dynamically loading data

onScrollEvent () {
      if (
        this.isScroll &&
        this.$refs.box.scrollHeight - this.$refs.box.scrollTop - this.$refs.box.clientHeight <= 0
      ) {
        this.loading = true
        if (this.ipagination.current == 1) {
          this.ipagination.current += 1
        }
        let param = {}
        param['pageNo'] = this.ipagination.current
        param['pageSize'] = this.ipagination.pageSize
        param['portraitId'] = this.portraitId
        postAction(this.url.list, { ...param }).then((res) => {
          this.loading = false
          if (res.success) {
            this.isScroll = res.records
            this.dataSource = this.dataSource.concat(res.result.records || res.result)
            this.waterFall();
          }
        })
        this.ipagination.current++
      }
    },

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:
  • JS realizes the effect of picture waterfall flow
  • Using js to achieve waterfall effect
  • How to use JS to implement waterfall layout of web pages
  • js to achieve waterfall flow layout (infinite loading)
  • 3 ways to implement waterfall layout with JavaScript
  • Have you learned how to implement JavaScript waterfall flow?

<<:  How to find and delete duplicate records in MySQL

>>:  Problems and solutions for installing Docker on Alibaba Cloud

Recommend

CSS animation property usage and example code (transition/transform/animation)

During development, a good user interface will al...

CentOS 8 is now available

CentOS 8 is now available! CentOS 8 and RedHat En...

Example to explain the size of MySQL statistics table

Counting the size of each table in each database ...

Troubleshooting the reasons why MySQL deleted records do not take effect

A record of an online MySQL transaction problem L...

MySql 5.7.20 installation and configuration of data and my.ini files

1. First download from the official website of My...

React sample code to implement automatic browser refresh

Table of contents What is front-end routing? How ...

Implementation of Vue large file upload and breakpoint resumable upload

Table of contents 2 solutions for file upload Bas...

Knowledge about MySQL Memory storage engine

Knowledge points about Memory storage engine The ...

How to solve the problem that Seata cannot use MySQL 8 version

Possible reasons: The main reason why Seata does ...

Details on using JS array methods some, every and find

Table of contents 1. some 2. every 3. find 1. som...

Installation and configuration method of vue-route routing management

introduce Vue Router is the official routing mana...

Vue axios interceptor commonly used repeated request cancellation

introduction The previous article introduced the ...

Tips on setting HTML table borders

For many people who are new to HTML, table <ta...

Steps for Docker to build a private warehouse Harbor

Harbor Harbor is an open source solution for buil...