GithubHelp home page GithubHelp logo

birdchang / vue-waterfall-easy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lfyfly/vue-waterfall-easy

0.0 1.0 0.0 1.57 MB

vue瀑布流组件(vue waterfall component)

License: MIT License

JavaScript 57.32% HTML 0.94% Vue 40.54% CSS 1.20%

vue-waterfall-easy's Introduction

vue-waterfall-easy 2.x

  1. This is a vue component that contains waterfall flow layout and infinite scroll loading
  2. Compared to other implementations,there is no need to specify the width and height of the image in the returned data
  3. It is because of the second item that the image is preloaded and then layout
  4. Responsive layout,adapt mobile
  5. Simple to use

1. Usage

1.1 Installation

npm install vue-waterfall-easy --save

1.2 es6 import

import vueWaterfallEasy from 'vue-waterfall-easy'
export default {
  name: 'app',
  components: {
    vueWaterfallEasy
  }
}

1.3 scripts import

download vueWaterfallEasy.js

<script src="path/to/vue/vue.js"></script>
<script src="path/to/vueWaterfallEasy.js"></script>
new Vue({
  el: '#app',
  components: {
    vueWaterfallEasy
  }
})

1.4 Supports require.js and sea.js module import

2. Basic example

html

<vue-waterfall-easy :imgsArr="imgsArr" @scrollReachBottom="getData"></vue-waterfall-easy>

getData method new request returned data should merged with the original data

js

import vueWaterfallEasy from './vue-waterfall-easy/vue-waterfall-easy.vue'
import axios from 'axios'
export default {
  name: 'app',
  data() {
    return {
      imgsArr: [],
      group: 0,// request param
    }
  },
  components: {
    vueWaterfallEasy
  },
  methods: {
    getData(group) {
      // In the real environment,the backend will return a new image array based on the parameter group.
      // Here I simulate it with a stunned json file.
      axios.get('./static/mock/data.json?group=' + this.group)
        .then(res => {
          this.imgsArr = this.imgsArr.concat(res.data)
          group++
        })
    },
  },
  created() {
    this.getData()
  }
}

more detail see App.vue file

3. Props

props type default description
width Number - Container width,default is 100% relative parent element width,Due to the responsiveness,all its parent's width must be 100% relative to the browser window at this time,See the example after the table
**If it is fixed width, you must set the width prop **, not just its parent element set fixed width
height Number - Container height,default is 100% relative parent element height
The parent element must have a height when the height prop is not passed
gap Number 20 space between pictures(px)
imgsArr Array [] required
Data used to render the waterfall stream
Each array element is an object and must have src and href attributes.
The src attribute represents the SRC attribute of the picture
The href attribute represents the link to click to jump
if your key is not src and href, you can use the two properties of srcKey and hrefKey to do the key value replacement.
srcKey String 'src' When the key value of your picture address is not src, you can use this property to replace it.
hrefKey String 'href' When the key value of your picture address is not href, you can use this property to replace it.
imgWidth Number 240 The width of the picture(px)
maxCols Number 5 Waterfall shows the maximum number of columns
linkRange String 'card' Identify click to trigger jump link range
value:
'card' Whole card range
'img' image range
'custom' Customize the link range through slots
isRouterLink Boolean false Render the a tag when the value is false
Render the router-link component when the value is true
reachBottomDistance Number 0 The distance(px) from the bottom of the container when the scrolling triggers the scrollReachBottom event
loadingDotCount Number 3 The number of default loading animation dots
loadingDotStyle Object null The style object of the small dots in the default loading element
loadingTimeOut Number 500 Preloading events less than 500ms milliseconds do not display loading animations,increasing the user experience

4. Event

event name description
scrollReachBottom When the scroll bar scrolls to the bottom,it is used to trigger a request for new image data
preloaded Trigger every time image preloading is completed
click Trigger when the card is clicked,look at an example under the table

click event demo

<vue-waterfall-easy :imgsArr="imgsArr" @scrollReachBottom="getData" @click="clickFn"></vue-waterfall-easy>
  clickFn(event, { index, value }) {
    // Prevent a tag jump
    event.preventDefault()
    // Do it only when you click on the image
    if (event.target.tagName.toLowerCase() == 'img') {
      console.log('img clicked',index, value)
    }
  }

5. slot

5.1 default slot

Custom picture description element

parameter

parameterpar description
props.index The index of the image in the data array,starting from 0
props.value The value of imgsArr item
<vue-waterfall-easy :imgsArr="imgsArr" @scrollReachBottom="getData">
  <div class="img-info" slot-scope="props">
    <p class="some-info">picture index: {{props.index}}</p>
    <p class="some-info">{{props.value.info}}</p>
  </div>
</vue-waterfall-easy>

5.2 slot="loading"

Custom loading element

<div slot="loading" slot-scope="{isFirstLoad}">
  <div slot="loading" v-if="isFirstLoad">first-loading...</div>
  <div v-else="v-else">loading...</div>
</div>

5.3 slot="waterfall-head"

Waterfall container head slot

<vue-waterfall-easy :imgsArr="imgsArr" @scrollReachBottom="getData">
  <div slot="waterfall-head">waterfall-head</div>
</vue-waterfall-easy>

6. Adapted mobile

Don't forget to add following code in index.html <head>

<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">

vue-waterfall-easy's People

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.