Skip to content

瀑布流 Waterfall


瀑布流展示图片列表

说明

宽度固定,图片等比例缩放;使用JS获取每张图片宽度和高度,结合 relativeabsolute 定位计算每个图片的位置 topleft,保证每张新的图片都追加在当前高度最小的那列末尾

基本使用

Show Code
vue
<script setup lang="ts">
import { ref, onBeforeMount } from 'vue'

const images = ref<any[]>([])

function loadImages () {
  for (let i = 1; i <= 10; i++) {
    images.value.push({
      title: `image-${i}`,
      link: '',
      src: `https://cdn.jsdelivr.net/gh/themusecatcher/resources@0.0.5/${i}.jpg`
    })
  }
}
onBeforeMount(() => { // 组件已完成响应式状态设置,但未创建DOM节点
  loadImages()
})
</script>
<template>
  <Waterfall :images="images" />
</template>

自定义展示

Show Code
vue
<script setup lang="ts">
import { ref, onBeforeMount } from 'vue'

const images = ref<any[]>([])

function loadImages () {
  for (let i = 1; i <= 10; i++) {
    images.value.push({
      title: `image-${i}`,
      link: '',
      src: `https://cdn.jsdelivr.net/gh/themusecatcher/resources@0.0.5/${i}.jpg`
    })
  }
}
onBeforeMount(() => { // 组件已完成响应式状态设置,但未创建DOM节点
  loadImages()
})
</script>
<template>
  <Waterfall :images="images" :column-count="4" :column-gap="10" background-color="#e1faeb" :border-radius="6" />
</template>

APIs

参数说明类型默认值必传
images图片数组Image[][]true
columnCount要划分的列数number3false
columnGap各列之间的间隙,单位pxnumber20false
width瀑布流区域的总宽度string | number'100%'false
borderRadius瀑布流区域和图片圆角,单位pxnumber8false
backgroundColor瀑布流区域背景填充色string'#F2F4F8'false

Image Type

名称说明类型必传
title图片名称stringfalse
src图片地址stringtrue

Released under the MIT License.