Code Monkey home page Code Monkey logo

vue-waterfall-plugin's Introduction

Vue2 瀑布流组件

vue 瀑布流插件,支持 PC 和移动端,支持 animate 的所有动画效果,支持图片懒加载

在线演示地址

vue3 版本

安装

npm install vue-waterfall-plugin

使用

import { LazyImg, Waterfall } from 'vue-waterfall-plugin'
import 'vue-waterfall-plugin/dist/style.css'
<Waterfall :list="list">
  <template #item="{ item, url, index }">
    <div class="card">
      <LazyImg :url="url" />
      <p class="text">这是内容</p>
    </div>
  </template>
</Waterfall>
data: {
  list: [
    {
      src: "xxxx.jpg",
      ...
    }
    ...
  ]
}

作用域插槽返回了3个字段: item 原始数据, url 图片资源, index 卡片索引

Props 参数

参数名 类型 默认值 描述
list Array [] 列表数据
rowKey String id 数据唯一的字段,比如列表里面的id, 如果要删除卡片,该字段为必填
imgSelector String src 图片字段选择器,如果层级较深,使用 xxx.xxx.xxx 方式
width Number 200 卡片在 PC 上的宽度
breakpoints Object breakpoints 自定义行显示个数,主要用于对移动端的适配
gutter Number 10 卡片之间的间隙
hasAroundGutter Boolean true 容器四周是否有 gutter 边距
animationPrefix String animate__animated animate.css 的动画绑定 className,默认的是 4.x.x 版本,如果想使用老版本,只需要改成 animated 即可
animationEffect String fadeIn 卡片入场动画,默认只有 fadeIn,引入 animation.css 后可使用其他动画
animationDuration Number 1000 动画执行时间(单位毫秒)
animationDelay Number 300 动画延迟(单位毫秒)
backgroundColor String #ffffff 背景颜色
loadProps Object loadProps 加载的图片和失败的图片
lazyload Boolean true 是否开启懒加载
delay Number 300 布局刷新的防抖时间,默认 300ms 内没有再次触发才刷新布局。(图片加载完成;容器大小、listwidthgutterhasAroundGutter变化时均会触发刷新)

breakpoints

breakpoints: {
  1200: { //当屏幕宽度小于等于1200
    rowPerView: 4,
  },
  800: { //当屏幕宽度小于等于800
    rowPerView: 3,
  },
  500: { //当屏幕宽度小于等于500
    rowPerView: 2,
  }
}

loadProps

import loading from 'assets/loading.png'
import error from 'assets/error.png'
loadProps: {
  loading,
  error
}

懒加载图片样式覆盖,需要将覆盖样式放在全局才能生效

.lazy__img[lazy=loading] {
  padding: 5em 0;
  width: 48px;
}

.lazy__img[lazy=loaded] {
  width: 100%;
}

.lazy__img[lazy=error] {
  padding: 5em 0;
  width: 48px;
}

vue-waterfall-plugin's People

Contributors

chaobingzhu avatar heikaimu avatar kaiter-plus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

vue-waterfall-plugin's Issues

当浏览器宽度小于1200时,如果waterfall宽度并非浏览器宽度时(例如有侧边栏),会超出浏览器宽度

非常感谢这个项目,使用起来非常简单,效果也很好!

这里有一个问题:

  data () {
    return {
      screenWidth: document.body.clientWidth,
      itemsGutter: [],
      itemsPosX: [],
      canRun: true
    }
  },
  computed: {
    itemWidth() {
      const { screenWidth, gutter, width, phoneCol } = this;
      if (screenWidth >= 1200) {
        return width;
      } else {
        return (screenWidth - (phoneCol + 1) * gutter) / phoneCol;
      }
    }
  },

当浏览器宽度小于1200时,会重新计算waterfall的宽度。计算的公式是(screenWidth - (phoneCol + 1) * gutter) / phoneCol。这里不应该取screenWidth,应该取parent的宽度来计算,否则页面可能会超过浏览器宽度。

请问,是否有办法在父组件覆盖itemWidth函数,或者作者帮忙更新一下?

Cannot read property 'clientWidth' of undefined

Uncaught TypeError: Cannot read property 'clientWidth' of undefined
    at VueComponent.resize (webpack-internal:///./node_modules/cache-loader/dist/cjs.js?!./node_modules/babel-loader/lib/index.js!
./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader/lib/index.js?!./node_modules/vue-waterfall-plugin/lib/Waterfall.vue?vue&type=script&lang=js&:237)
    at eval (webpack-internal:///./node_modules/vue-waterfall-plugin/lib/utils/debounce.js:8)

关于1200分辨率阈值的问题

个人感觉1200宽的分辨率也可以显示很多信息,无需被视为低分辨率设备,如11寸ipad pro的浏览器分辨率为834*1194,略有些尴尬。请问是否可以增加用户自定义分辨率阈值的入口?

页面使用多个组件出现异常

1.一个页面使用了n个子组件,这个数量是动态的,根据接口配置
2.子组件使用了瀑布流组件做布局,会出现部分子组件高度坍塌
image

希望可以移除sass

安装后运行提示缺少依赖,安装sass后还是报错,搜索了一下是sass版本太高,降低版本才解决

懒加载的第一次加载图片。

懒加载的第一次加载图片,chorom Network 数据项会显示 同一张图片会加载两次 而且Status项非 304, size项 非memorychache。这是为什么?

提几点建议

  • 增加一个等高的显示方案
  • 在有充足的数据前提下,预先设置 imgdiv 父组件的宽高为 img 的宽高,background-color 属性设置为 img 目标图像的主色调,像 Twitter 那样,在图片还没加载完成时能获得一个较好的体验。

可以的话希望能考虑一下。

谢谢

加载图片的跨域能否设置成可选

export function loadImage(url) {
return new Promise((resolve, reject) => {
const image = new Image()
image.onload = () => {
resolve(image)
}
image.onerror = () => {
reject(new Error('Image load error'))
}
image.crossOrigin = 'Anonymous' // 支持跨域图片
image.src = url
})
}

  1. 图片跨域能支持可选吗?

2.图片的大小是否有限制,图片超过200kb,页面展示一直是img error,用不用懒加载都是一样

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.