实现效果
(最近加班有点严重,睡眠不足,所以没有认真的排版,效果是出来了。。将就一下吧)
这是移动端和pc端都可以实现的,基于javascript,进行高度捕获差值去实现的。
html部分
<template>
<div class="row f12" id="app-mains">
<div class="col-6">
<div class="card">
<div class="card-body">
<p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
</div>
</div>
</div>
<div class="col-6">
<div class="card">
<div class="card-body">
<p class="card-text">This is a short card.</p>
</div>
</div>
</div>
<div class="col-6">
<div class="card">
<div class="card-body">
<p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
</div>
</div>
</div>
<div class="col-6">
<div class="card">
<div class="card-body">
<p class="card-text">This is a short card.</p>
</div>
</div>
</div>
<div class="col-6">
<div class="card">
<div class="card-body">
<p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
</div>
</div>
</div>
<div class="col-6">
<div class="card">
<div class="card-body">
<p class="card-text">This is a short card.</p>
</div>
</div>
</div>
</div>
</template>

复制代码
css部分
由于这本来是在公司实现的,公司的代码就不展示了,处理了一下,变成移动端了,可是是基于bootstrap5.0去实现的,有点懒
<style scoped>
#app-mains{position: relative}
</style>
<style>
.col-6{padding-left: 0!important;padding-right: 0!important;margin-top: 0!important;}
</style>
复制代码
js部分
<script lang="ts">
import { defineComponent, reactive, toRefs, onMounted } from 'vue'
import 'bootstrap/dist/css/bootstrap.min.css'
interface waterfallFlow {
waterfallFlowHeight: Array
}
export default {
name: 'demo',
setup() {
const state: waterfallFlow = reactive({
waterfallFlowHeight: [0, 0]
})
const waterfallFlowFun = () => {
const dom = document.querySelectorAll('.col-6')
dom.forEach((item: any) => {
item.style.position = 'absolute'
const minIndex = filterMin()
item.style.top = state.waterfallFlowHeight[minIndex] + 10 + 'px'
item.style.left = minIndex * (100 / 2) + '%'
state.waterfallFlowHeight[minIndex] += item.querySelector('.card').offsetHeight + 10
})
}
const filterMin = () => {
const min = Math.min.apply(null, state.waterfallFlowHeight)
return state.waterfallFlowHeight.indexOf(min)
}
const _isMobile = () => {
let flag = navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)
return flag
}
onMounted(() => waterfallFlowFun())
}
}
</script>
复制代码
讲解:
waterfallFlowHeight 这个变量,如果你想两行的瀑布流,这里数据就两个数据,如果三行就三个,以此类推
filter这个函数,是用了Math.min.apply去取最小值(Math.max.apply是取最大值) 这个函数取到了上一行的高度最小值
_isMobile() 这个函数,是用来判断pc端还是web端。由于我是做响应式,在移动端是不需要这个特效的,所以我只判断在pc端实现
结尾
搞掂收工,有不懂的尽管问,我有空就会回复的啦
大佬们,感兴趣可以关注我公众号鸭,现在还是个位数呢,委屈屈…
人懒,不想配图,望能帮到大家
公众号:
小何成长
,佛系更文,都是自己曾经踩过的坑或者是学到的东西有兴趣的小伙伴欢迎关注我哦,我是:
何小玍。
大家一起进步鸭
记叙文:
技术文
乱七八糟系列
vue系列
- 【Vue版本 – 前端实践系列之九】登录注册界面千篇一律?教你做个炫酷的!
- vue3的setup和Ref 语法
- vue3的provide和inject
- [项目篇]vue3 + vite + vant + typescript – 第一天
- [项目篇]vue3+ts 封装request请求,storage缓存,config请求信息抽离 – 第二天
- [项目篇]vue3+ts 封装底部tabbar – 第三天
- [项目篇]vue3+ts canvas实现贝塞尔曲线波浪特效 – 第四天
- [项目篇]vue3+ts 今天来理解一下自定义hooks – 第五天
typescript系列
- 手摸手一起学习Typescript第一天,数据类型和vscode的搭配typescript
- 手摸手一起学习Typescript第二天,interface接口和readonly属性
- 手摸手一起学习Typescript第三天 – 函数Function
- 手摸手一起学习Typescript第四天 – 类型推论,联合类型 和 类型断言
- 手摸手一起学习Typescript第五天 – Class 类 / 类与接口
- 手摸手一起学习Typescript第六天 – 泛型 Generics / 泛型约束 / 泛型与类和接口
- 手摸手一起学习Typescript第七天 – 类型别名 和 交叉类型
- 手摸手一起学习Typescript第八天 – 声明文件 、内置类型
react-native系列
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END