# vue-waterfall2

> waterfall adaptive plugin for vue and support lazy load , very easy!

Latest version **1.10.9** (published 2024-06-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install vue-waterfall2
pnpm add vue-waterfall2
yarn add vue-waterfall2
bun add vue-waterfall2
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.10.9 |
| Published | 2024-06-19 |
| First published | 2018-11-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >= 6.0.0 |
| Dependencies | 1 |
| Unpacked size | 19.9 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Devin |
| Maintainers | rise-devin |
| Keywords | vue, vue3, vue3-waterfall, vue-waterfall, vue-waterfall2, waterfall |

## Links

- npm: https://www.npmjs.com/package/vue-waterfall2
- npm.io page: https://npm.io/package/vue-waterfall2

## Dependencies (1)

- [vue](https://npm.io/package/vue.md) 2.7.0

## Recent versions

- 1.10.9 (latest) — 2024-06-19
- 2.0.7 — 2024-01-09
- 2.0.6 — 2024-01-09
- 2.0.5 — 2023-11-15
- 2.0.4 — 2023-11-15
- 2.0.3 — 2023-11-09
- 1.10.7 — 2023-11-07
- 2.0.2 — 2023-11-07
- 1.10.7-beta.1 — 2023-11-07
- 2.0.1 — 2023-11-07
- 2.0.0 — 2023-11-03
- 2.0.0-beta.1 — 2023-11-03
- 1.10.6 — 2022-11-11
- 1.10.5 — 2022-09-05
- 1.10.4 — 2022-09-05
- … 72 more at https://npm.io/package/vue-waterfall2/versions

## README

#### [中文版文档](https://github.com/AwesomeDevin/vue-waterfall2/blob/master/CHINESE-README.md)

# Note: vue-waterfall2@2.x is adapt for vue3, if your app is vue2, please use vue-waterfall2@1.10.x, [1.10.x document](https://github.com/AwesomeDevin/vue-waterfall2/tree/1.10.6)

# vue-waterfall2 
 1. auto adaption for width and height
 2. High degree of customization
 3. Swipe to the bottom to trigger on pc/android, pull up to trigger on ios
 4. Support lazy load(attribute with `lazy-src`)
 5. Easy to use, for PC/ios/android

![The demo on mobile device](https://raw.githubusercontent.com/AwesomeDevin/vue-waterfall2/master/src/assets/gifhome_240x514_17s.gif)


If you have some questions,welcome to describe issues、suggestions;Thank you for your Star !   
[Welcome to my blog  ！！！](https://github.com/AwesomeDevin/blog)


## Demo
[Common Demo](https://awesomedevin.github.io/vue-waterfall2/#/)  
[Lazyload Demo](https://awesomedevin.github.io/vue-waterfall2/#/lazy)  
[Code Demo](https://codesandbox.io/embed/vue-template-99ps6)





[GITHUB](https://github.com/Rise-Devin/vue-waterfall2)
```
npm i 
npm run dev
```

## Installation
```
 npm i vue-waterfall2@latest --save
```

## <waterfall> Props
Name | Default | Type | Desc
-------- | -------- | -------- | --------
height | null | Number | height of container
col | 2  | Number |  The number of column
width | null | Number | The width of each column
gutterWidth | 10 | Number | The value of margin
data | [] | Array | data
isTransition | true | Boolean | load image with transition
lazyDistance | 300 | Number | The distance of image lazy loading
loadDistance | 300 | Number | The distance of loadmore
  
## Lazy Load
For images that need to be loaded lazily, the 'lazy-src' attribute needs to be used
```html
<waterfall :col='col'   :data="data"     >
  <img v-if="item.img" :lazy-src="item.img" alt="load error"  />
</waterfall>
```

## <waterfall> Events
Name | Data |   Desc
-------- | --- | -------- 
loadmore | - | Scroll to the bottom to trigger on PC /  pull up to trigger on Mobile  
scroll | obj | Scroll to trigger and get the infomation of scroll
finish | - | finish render
  
## $waterfall API
```
this.$waterfall.forceUpdate()   //forceUpdate
```

## Usage
Notes:
  1. when using `rem` to layout, calculate the width after adaptation before passing the value.
  2. Use the parent component of 'waterfall' if there is a problem with the style, remove CSS `scoped` and try it
##### main.js
```javascript
import { createApp } from "vue";
import waterfall from 'vue-waterfall2'

const app = createApp(App)
app.use(waterfall)
```
##### app.vue
```javascript
<template>
  <div class="container-water-fall">
    <div><button  @click="loadmore">loadmore</button> <button @click="mix">mix</button> <button @click="switchCol('5')">5列</button> <button @click="switchCol('8')">8列</button> <button @click="switchCol('10')">10列</button> </div>

    <waterfall :col='col' :width="itemWidth" :gutterWidth="gutterWidth"  :data="data"  @loadmore="loadmore"  @scroll="scroll"  >
      <div class="cell-item" v-for="(item,index) in data">
        <div class="item-body">
            <div class="item-desc">{{item.title}}</div>
            <div class="item-footer">
                <div class="avatar" :style="{backgroundImage : `url(${item.avatar})` }"></div>
                <div class="name">{{item.user}}</div>
                <div class="like" :class="item.liked?'active':''" >
                    <i ></i>
                    <div class="like-total">{{item.liked}}</div>  
                </div>
            </div>
        </div>
      </div>
    </waterfall>
    
  </div>
</template>


/*
  notes:
  1. when using `rem` to layout, calculate the width after adaptation before passing the value.
  2. Use the parent component of 'waterfall' if there is a problem with the style, remove CSS 'scoped' and try it
*/

import Vue from 'vue'
	export default{
	    data(){
	        return{
	            data:[],
	            col:5,
	        }
	    },
	    computed:{
	      itemWidth(){  
	            return (138*0.5*(document.documentElement.clientWidth/375))  #rem to layout, Calculate the value of width 
	      },
	      gutterWidth(){
	            return (9*0.5*(document.documentElement.clientWidth/375)) #rem to layout, Calculate the value of margin 
	      }
	    },
	    methods:{
            scroll(scrollData){
                console.log(scrollData)
            },
	        switchCol(col){
	            this.col = col
	            console.log(this.col)
	      },
	      loadmore(index){
	            this.data = this.data.concat(this.data)
	      }
	    }
	}
```

---
_Source: https://npm.io/package/vue-waterfall2 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
