vue当中的猫咪瀑布流

article/2025/9/22 5:27:27

效果图

请添加图片描述

utils

  • utils的index文件
//判断是否是移动端 
export const isMobile = () => {return !!navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)
}

cart.vue

src里面的cart.vue
用来写瀑布流的页面
<template><div id="waterfall" ref="waterfall"><divclass="img-box default-card-animation"v-for="(item, index) in imgsArr_c":key="index":style="{ width: imgWidth + 'px', height: item._height + 'px' }"ref="imgBox"><img :data-src="item.src" /><!-- <div>100100100100</div> //这个是带文字的写法 --></div></div>
</template>
<script>
// 判断是否移动端显示2列
import { isMobile } from "../utils/index";
export default {name: "waterfall",data() {return {imgsArr: this.$store.state.list,//这个是我放在vuex里了 所以这样写 具体看个人引入imgsArr_c: [], // 渲染的图片imgCol: 5, // 图片列数imgGap: 5, // 图片间间隔loadedCount: 0,imgBoxEls: [], // 所有 img-box 元素beginIndex: 0,colsHeightArr: [], // 保存当前每一列的高度reachBottomDistance: 20, // 滚动触底距离,触发加载新图片viewHeight: 0, // 窗口视图大小};},computed: {isMobile() {return isMobile();},// 容器 waterfall 的宽度waterfallWidth() {return this.$refs["waterfall"].clientWidth;},// 图片宽度imgWidth() {return this.colWidth - 2 * this.imgGap;},// 列宽度colWidth() {return this.waterfallWidth / this.colNum;},// 列数colNum() {return this.isMobile ? 2 : this.imgCol;},},watch: {imgsArr(newVal, oldVal) {if (this.imgsArr_c.length > newVal.length ||(this.imgsArr_c.left > 0 && newVal[0] && !newVal[0]._height))this.reset();this.preLoad();},},methods: {// 预加载 设置图片宽高preLoad() {// forEach 无法通过 item 直接修改数组元素,需用数组下标修改this.imgsArr.forEach((item, index) => {if (index < this.loadedCount) return;if (!item.src) {this.imgsArr[index]._height = "0";++this.loadedCount;if (this.imgsArr.length === this.loadedCount) {this.preloaded();}} else {let img = new Image();img.src = item.src;img.onload = img.onerror = (e) => {// 若加载失败则设置图片高度与宽度一致,加载成功则动态计算图片高度this.imgsArr[index]._height =e.type === "load"? Math.round(this.imgWidth * (img.height / img.width)): this.imgWidth;if (e.type === "error") {this.imgsArr[index]._error = true;}++this.loadedCount;if (this.imgsArr.length === this.loadedCount) {this.preloaded();}};}});},preloaded() {this.imgsArr_c = [].concat(this.imgsArr);this.$nextTick(() => {this.waterfall();});},// waterfall 布局waterfall() {// 等到整个视图都渲染完毕再执行this.imgBoxEls = this.$refs["imgBox"];if (!this.imgBoxEls) return;let top, left, height;if (this.beginIndex === 0) this.colsHeightArr = [];for (let i = this.beginIndex; i < this.imgBoxEls.length; ++i) {if (!this.imgBoxEls[i]) return;height = this.imgBoxEls[i].offsetHeight;// 第一行if (i < this.colNum) {this.colsHeightArr.push(height);top = 0;left = i * this.colWidth;} else {// 找到最低的高度和其索引let minHeight = Math.min.apply(null, this.colsHeightArr);let minIdx = this.colsHeightArr.indexOf(minHeight);top = minHeight;left = minIdx * this.colWidth;this.colsHeightArr[minIdx] += height;}// 设置 img-box 位置this.imgBoxEls[i].style.top = top + "px";this.imgBoxEls[i].style.left = left + "px";// 当前图片在窗口内,则加载if (top < this.viewHeight) {let imgEl = this.imgBoxEls[i].children[0];imgEl.src = imgEl.getAttribute("data-src");imgEl.style.opacity = 1;imgEl.style.transform = "scale(1)";}}this.beginIndex = this.imgBoxEls.length;},reset() {this.imgsArr_c = [];this.beginIndex = 0;this.loadedCount = 0;},// 滚动触底事件scrollFn() {let minHeight = Math.min.apply(null, this.colsHeightArr);// 滚动条滚动的高度let scrollTop =window.pageYOffset ||document.documentElement.scrollTop ||document.body.scrollTop;// 到达最底层的高度最低的一列,则触发 handleReachBottom 方法if (scrollTop + this.viewHeight > minHeight - this.reachBottomDistance) {this.handleReachBottom();}// 图片懒加载this.imgBoxEls.forEach((imgBoxEl, index) => {let imgEl = imgBoxEl.children[0];// 若已加载,则跳过if (imgEl.src) return;// 当前图片所处的高度let top = imgBoxEl.style.top;top = Number.parseFloat(top.slice(0, top.length - 2));// 图片已到达可视范围,则加载if (scrollTop + this.viewHeight > top) {imgEl.src = imgEl.getAttribute("data-src");imgEl.style.opacity = 1;imgEl.style.transform = "scale(1)";}});},scroll() {window.onscroll = this.throttle(this.scrollFn, 500);},handleReachBottom() {this.imgsArr = this.imgsArr.concat(this.imgsArr);},// 节流函数throttle(fn, time) {let canRun = true;return function () {if (!canRun) return;canRun = false;setTimeout(() => {fn.apply(this);canRun = true;}, time);};},},mounted() {this.viewHeight =document.documentElement.clientHeight == 0? document.body.clientHeight: document.documentElement.clientHeight;this.preLoad();this.scroll();},
};
</script>
<style scoped lang="scss">
#waterfall {width: 100%;position: relative;@keyframes show-card {0% {transform: scale(0.5);}100% {transform: scale(1);}}.img-box {border: 1px solid red;position: absolute;// width: 100%;// height: 300px !important;border-radius: 10px;padding: 5px;padding-left: 0;img {width: 100%;border: 1px solid black;//height: 80%;border-radius: 10px;opacity: 0;transform: scale(0.5);transition: all 0.6s;transition-delay: 0.1s;}}
}
</style>

json

{"imgsArr": [{"src": "https://gimg2.baidu.com/image_search/src=http%3A%2F%2F5b0988e595225.cdn.sohucs.com%2Fq_70%2Cc_zoom%2Cw_640%2Fimages%2F20190210%2F8534c3170a314d83b104d04aa120a040.jpeg&refer=http%3A%2F%2F5b0988e595225.cdn.sohucs.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1638440861&t=d15af814c4ae34b95bc60e35efc88e4c","href": "https://www.baidu.com","info": "我是第一张图片","headerText": "测试"},{"src": "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fwww.desktx.com%2Fd%2Ffile%2Fwallpaper%2Fanimals%2F20160822%2F05128add3de7bc5acfa3a38612673e1d.jpg&refer=http%3A%2F%2Fwww.desktx.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1638440861&t=667c221c38da5abdb0ed7d34d87ef564","href": "https://www.baidu.com","info": "一些图片描述文字asdasdasdasdasdasasdasd","headerText": "测试"},{"src": "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fwww.yidianzhidao.com%2FUploadFiles%2Fimg_1_1195934273_1809290298_26.jpg&refer=http%3A%2F%2Fwww.yidianzhidao.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1638440861&t=220f9c21856a2bb0cc71f76ba0b5e2cc","href": "https://www.baidu.com","info": "一些图片描述文字"},{"src": "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fblog%2F201508%2F10%2F20150810150356_hnves.thumb.400_0.jpeg&refer=http%3A%2F%2Fb-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1638440861&t=0971bf1e69ad8e180fb704140d7a29b0","href": "https://www.baidu.com","info": "一些图片描述文字"},{"src": "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimage.biaobaiju.com%2Fuploads%2F20180211%2F01%2F1518282902-iSBdILoxsY.jpg&refer=http%3A%2F%2Fimage.biaobaiju.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1638440861&t=c4c6cd3890f420680e5db7f92a8d543c","href": "https://www.baidu.com","info": "一些图片描述文字"},{"src": "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimage.biaobaiju.com%2Fuploads%2F20190504%2F20%2F1556972126-MAGsvFyfEd.png&refer=http%3A%2F%2Fimage.biaobaiju.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1638440861&t=4ecd99f7107e39197378a2b7a04176c6","href": "https://www.baidu.com","info": "一些图片描述文字"},{"src": "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Ffile06.16sucai.com%2F2016%2F0506%2Ff43b5bab036349f7b4ffdef661da97a8.jpg&refer=http%3A%2F%2Ffile06.16sucai.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1638440861&t=fd805292f3f72e9d7ba51fc9f45245ea","href": "https://www.baidu.com","info": "一些图片描述文字"},{"src": "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic1.win4000.com%2Fpic%2F3%2F5a%2Ffe101126073_250_350.jpg&refer=http%3A%2F%2Fpic1.win4000.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1638440861&t=72446335a210920f58bf6c6e6a106abe","href": "https://www.baidu.com","info": "一些图片描述文字"},{"src": "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fbos.pgzs.com%2Frbpiczy%2FWallpaper%2F2015%2F1%2F22%2Fe975967d962e45a7af2863060371d81c-12.jpg&refer=http%3A%2F%2Fbos.pgzs.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1638440861&t=775ff5be8b8b1e9abc8848ff575e437d","href": "https://www.baidu.com","info": "一些图片描述文字"},{"src": "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.qqtn.com%2Fup%2F2017-11%2F2017110816281636782.jpg&refer=http%3A%2F%2Fpic.qqtn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1638440862&t=36bd6acad4963ad2d153b3a4e220a363","href": "https://www.baidu.com","info": "一些图片描述文字"},{"src": "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimage.biaobaiju.com%2Fuploads%2F20190624%2F14%2F1561358677-yVQerfxNJO.jpeg&refer=http%3A%2F%2Fimage.biaobaiju.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1638440862&t=25e73d0d95ee43d9b160bd0dfe24aa38","href": "https://www.baidu.com","info": "一些图片描述文字"},{"src": "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimage.biaobaiju.com%2Fuploads%2F20180211%2F01%2F1518282942-vBSpHErLKP.jpg&refer=http%3A%2F%2Fimage.biaobaiju.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1638440862&t=809ae8cf1c654bb83dbbab9437b8e276","href": "https://www.baidu.com","info": "一些图片描述文字"},{"src": "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.ivsky.com%2Fimg%2Ftupian%2Fpre%2F201611%2F09%2Fsugelan_zheer_mao-002.jpg&refer=http%3A%2F%2Fimg.ivsky.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1638440862&t=962fa67d0f3fff40553440ccb8b06ec4","href": "https://www.baidu.com","info": "一些图片描述文字"},{"src": "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fn.sinaimg.cn%2Fsinacn%2Fw640h399%2F20180301%2F9ce9-fwnpcns9232331.jpg&refer=http%3A%2F%2Fn.sinaimg.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1638441157&t=46c567a84e0172aa430f0d058ba9a92f","href": "https://www.baidu.com","info": "一些图片描述文字"},{"src": "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fn.sinaimg.cn%2Fsinacn%2Fw640h640%2F20180109%2F9e54-fyqnici8428669.jpg&refer=http%3A%2F%2Fn.sinaimg.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1638441197&t=70f9aec9253df0dcea506df28938327a","href": "https://www.baidu.com","info": "一些图片描述文字"},{"src": "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fwww.euro-premium.cn%2Fsites%2Fdefault%2Ffiles%2F2017%2F12%2F2017-12-18-609.jpg&refer=http%3A%2F%2Fwww.euro-premium.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1638441197&t=e67e19c5e29ebd66265d2ed779359002","href": "https://www.baidu.com","info": "一些图片描述文字"},{"src": "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fqqpublic.qpic.cn%2Fqq_public%2F0%2F0-2816258155-A3E56E8F829BF213072E703F23FC3DC1%2F0%3Ffmt%3Djpg%26size%3D21%26h%3D550%26w%3D410%26ppv%3D1.jpg&refer=http%3A%2F%2Fqqpublic.qpic.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1638441314&t=def05d46f7dee911d2a2a8bb306976d5","href": "https://www.baidu.com","info": "一些图片描述文字"},{"src": "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fwww.euro-premium.cn%2Fsites%2Fdefault%2Ffiles%2F2017%2F09%2F2017-09-30-110.jpg&refer=http%3A%2F%2Fwww.euro-premium.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1638441314&t=d4d758316d5f48f3800b59a2eec7dc46","href": "https://www.baidu.com","info": "一些图片描述文字"},{"src": "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fwww.goupuzi.com%2Fnewatt%2FMon_2004%2F1_183281_b959196b41fb01e.jpg&refer=http%3A%2F%2Fwww.goupuzi.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1638441314&t=663a187a9631164c450e2b3b3e1b8d92","href": "https://www.baidu.com","info": "一些图片描述文字"}]
}

参考链接https://blog.csdn.net/weixin_41018377/article/details/121396915

效果图

在这里插入图片描述

代码

<template><div class="waterfull"><h2>瀑布流布局</h2><div class="v-waterfall-content" id="v-waterfall"><divv-for="(img, index) in waterfallList":key="index"class="v-waterfall-item":style="{top: img.top + 'px',left: img.left + 'px',width: waterfallImgWidth + 'px',height: img.height,}"><img :src="img.src" alt="" /><p style="font-size: small; color: #666; margin: 4px">{{ img.title }}</p><pstyle="font-size: x-small;color: #9e9e9e;margin: 4px;padding-bottom: 6px;">{{ img.info }}</p></div></div></div>
</template><script>
export default {name: "v-waterfall",data() {return {waterfallList: [],imgArr: ["https://gimg2.baidu.com/image_search/src=http%3A%2F%2F5b0988e595225.cdn.sohucs.com%2Fq_70%2Cc_zoom%2Cw_640%2Fimages%2F20190210%2F8534c3170a314d83b104d04aa120a040.jpeg&refer=http%3A%2F%2F5b0988e595225.cdn.sohucs.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1638440861&t=d15af814c4ae34b95bc60e35efc88e4c","https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fwww.desktx.com%2Fd%2Ffile%2Fwallpaper%2Fanimals%2F20160822%2F05128add3de7bc5acfa3a38612673e1d.jpg&refer=http%3A%2F%2Fwww.desktx.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1638440861&t=667c221c38da5abdb0ed7d34d87ef564","https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fwww.yidianzhidao.com%2FUploadFiles%2Fimg_1_1195934273_1809290298_26.jpg&refer=http%3A%2F%2Fwww.yidianzhidao.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1638440861&t=220f9c21856a2bb0cc71f76ba0b5e2cc","https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fblog%2F201508%2F10%2F20150810150356_hnves.thumb.400_0.jpeg&refer=http%3A%2F%2Fb-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1638440861&t=0971bf1e69ad8e180fb704140d7a29b0","https://gimg2.baidu.com/image_search/src=http%3A%2F%2F5b0988e595225.cdn.sohucs.com%2Fq_70%2Cc_zoom%2Cw_640%2Fimages%2F20190210%2F8534c3170a314d83b104d04aa120a040.jpeg&refer=http%3A%2F%2F5b0988e595225.cdn.sohucs.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1638440861&t=d15af814c4ae34b95bc60e35efc88e4c","https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fwww.desktx.com%2Fd%2Ffile%2Fwallpaper%2Fanimals%2F20160822%2F05128add3de7bc5acfa3a38612673e1d.jpg&refer=http%3A%2F%2Fwww.desktx.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1638440861&t=667c221c38da5abdb0ed7d34d87ef564","https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fwww.yidianzhidao.com%2FUploadFiles%2Fimg_1_1195934273_1809290298_26.jpg&refer=http%3A%2F%2Fwww.yidianzhidao.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1638440861&t=220f9c21856a2bb0cc71f76ba0b5e2cc","https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fblog%2F201508%2F10%2F20150810150356_hnves.thumb.400_0.jpeg&refer=http%3A%2F%2Fb-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1638440861&t=0971bf1e69ad8e180fb704140d7a29b0","https://gimg2.baidu.com/image_search/src=http%3A%2F%2F5b0988e595225.cdn.sohucs.com%2Fq_70%2Cc_zoom%2Cw_640%2Fimages%2F20190210%2F8534c3170a314d83b104d04aa120a040.jpeg&refer=http%3A%2F%2F5b0988e595225.cdn.sohucs.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1638440861&t=d15af814c4ae34b95bc60e35efc88e4c","https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fwww.desktx.com%2Fd%2Ffile%2Fwallpaper%2Fanimals%2F20160822%2F05128add3de7bc5acfa3a38612673e1d.jpg&refer=http%3A%2F%2Fwww.desktx.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1638440861&t=667c221c38da5abdb0ed7d34d87ef564","https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fwww.yidianzhidao.com%2FUploadFiles%2Fimg_1_1195934273_1809290298_26.jpg&refer=http%3A%2F%2Fwww.yidianzhidao.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1638440861&t=220f9c21856a2bb0cc71f76ba0b5e2cc","https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fblog%2F201508%2F10%2F20150810150356_hnves.thumb.400_0.jpeg&refer=http%3A%2F%2Fb-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1638440861&t=0971bf1e69ad8e180fb704140d7a29b0",],// waterfallImgWidth: 100,waterfallImgWidth: 200, // 每个盒子的宽度// waterfallImgCol: 5,// 瀑布流的列数waterfallImgCol: 2, // 瀑布流的列数waterfallImgRight: 10, // 每个盒子的右paddingwaterfallImgBottom: 10, // 每个盒子的下paddingwaterfallDeviationHeight: [],imgList: [],};},created() {// 触发入口for (let i = 0; i < this.imgArr.length; i++) {// this.imgList.push(this.imgArr[Math.round(Math.random() * 8)]);// 图片随机显示this.imgList.push(this.imgArr[i]);}},mounted() {this.calculationWidth();},methods: {//计算每个图片的宽度或者是列数calculationWidth() {let domWidth = document.getElementById("v-waterfall").offsetWidth;if (!this.waterfallImgWidth && this.waterfallImgCol) {this.waterfallImgWidth =(domWidth - this.waterfallImgRight * this.waterfallImgCol) /this.waterfallImgCol;} else if (this.waterfallImgWidth && !this.waterfallImgCol) {this.waterfallImgCol = Math.floor(domWidth / (this.waterfallImgWidth + this.waterfallImgRight));}//初始化偏移高度数组this.waterfallDeviationHeight = new Array(this.waterfallImgCol);for (let i = 0; i < this.waterfallDeviationHeight.length; i++) {this.waterfallDeviationHeight[i] = 0;}this.imgPreloading();},//图片预加载imgPreloading() {for (let i = 0; i < this.imgList.length; i++) {let aImg = new Image();aImg.src = this.imgList[i];aImg.onload = aImg.onerror = (e) => {let imgData = {};imgData.height = (this.waterfallImgWidth / aImg.width) * aImg.height;// 如果获取的是数据在这边请求调取数据 这里不详细描述imgData.src = this.imgList[i];imgData.title = "标题"; // 说明文字(也可以自己写数组,或者封装json数据,都可以,但是前提是你会相关操作,这里不赘述)imgData.info = "详情说明:啦啦啦啦啦"; // 说明文字this.waterfallList.push(imgData);this.rankImg(imgData);};}},//瀑布流布局rankImg(imgData) {let {waterfallImgWidth,waterfallImgRight,waterfallImgBottom,waterfallDeviationHeight,waterfallImgCol,} = this;let minIndex = this.filterMin();imgData.top = waterfallDeviationHeight[minIndex];imgData.left = minIndex * (waterfallImgRight + waterfallImgWidth);// waterfallDeviationHeight[minIndex] += imgData.height + waterfallImgBottom;// 不加文字的盒子高度waterfallDeviationHeight[minIndex] +=imgData.height + waterfallImgBottom + 56; // 加了文字的盒子高度,留出文字的地方(这里设置56px)console.log(imgData);},/*** 找到最短的列并返回下标* @returns {number} 下标*/filterMin() {const min = Math.min.apply(null, this.waterfallDeviationHeight);return this.waterfallDeviationHeight.indexOf(min);},},
};
</script><style scoped>
.waterfull {width: 100%;
}
.v-waterfall-content {/* 主要 */width: 100%;height: 100vh;position: relative;/* 次要:设置滚动条,要求固定高度 */overflow-y: auto;
}.v-waterfall-item {/* 主要 */float: left;position: absolute;
}.v-waterfall-item img {/* 主要 *//* width: auto;height: auto; */width: 90%;height: auto;/* 次要 */border-radius: 6px;
}
</style>

参考代码


http://chatgpt.dhexx.cn/article/kc5MnDJX.shtml

相关文章

iOS开发storyboard拖拽tableView: Static cells的使用

从 object library 中&#xff0c;拖拽一个 UITableView 到 main.storyboard的 UIViewController 中&#xff1b; 设置 table view 的类型为&#xff1a; Static Cells。 设置的方法&#xff1a; 选中 tableview&#xff0c; 在 attributes inspector 中设置。 这时会报错。…

芒果iOS开发之NSComparisonResult比较结果

在学习NSString的时候&#xff0c;可能会经常遇到比较两个字符串的大小&#xff0c;系统已经提供了字符串比较的函数&#xff1a; [objc] view plain copy print ? <span style"font-size:24px;">- (NSComparisonResult)compare:(NSString *)string; </…

iOS用户行为追踪——无侵入埋点

本文章系作者原创文章&#xff0c;如需转载学习&#xff0c;请注明该文章的原始出处和网址链接。   在阅读的过程中&#xff0c;如若对该文章有不懂或值得优化的建议&#xff0c;欢迎大家加QQ&#xff1a;690091622 进行技术交流和探讨。 前言&#xff1a;   前几日做项目,…

猫猫学习ios 之第三方登录友盟实现

一&#xff1a;集成友盟分享 做第三方登录现在大多数用友盟&#xff0c;友盟之中做第三方登录的时候首先下载sdk&#xff0c;然后自己看文档&#xff0c;其实友盟的官方文档写的已经十分清楚了&#xff0c;这里自己写写&#xff0c;做一下笔记 二&#xff1a;详细 友盟&#…

【flutter】使用permission_handler配置android和 iOS的权限

文章目录 前言准备工作一、使用步骤1.使用的插件2.配置权限 二、代码示例三、结果截图 前言 flutter在pub.flutter-io.cn插件库中有很多的关于权限配置的插件&#xff0c;但是就我个人而言&#xff0c;比较推荐使用permission_handler这个插件。当我们打开permission_handler时…

Flutter 混合开发 - 03 百度地图定位功能 ios 篇

本节目标 创建 ios flutter 插件流程集成百度定位功能 视频 https://www.bilibili.com/video/BV1HT4y1L73i/ 代码 https://github.com/ducafecat/flutter_baidu_plugin_ducafecat/releases/tag/v1.0.3 百度平台部分 设置 AK https://lbsyun.baidu.com/apiconsole/key#/h…

iOS-Charts图表绘制一块平行X轴线性指标

养小猫咪的伙伴来我的店铺逛逛吧!抖音商城搜索#早睡早起的猫咪小铺子 最近做项目需要画柱状图和折线图&#xff0c;引入了第三方的图标库Charts。 这个图表库基本上能够满足大家对于图表绘制的需要&#xff0c;但是api接口的解释并不是很详细&#xff0c;该库有强大的功能&…

ios模拟器 - Simulator录制视频

养小猫咪的伙伴来我的店铺逛逛吧!抖音商城搜索#早睡早起的猫咪小铺子 1.进入终端&#xff0c;cd到要放置录屏文件的位置 2.输入命令 ,输入你的命名 xcrun simctl io booted recordVideo xxx.mov 提示&#xff1a;停止录屏 control c 最后进入到对应文件夹就可以找到录制好的…

猫猫学iOS之安装cocoapods

啥事cocoa pods 不解释&#xff0c;自己看这里只有一次安装流程&#xff0c;猫猫的安装流程。 打开命令行&#xff0c;我用的是ruby安装&#xff0c;mac自带ruby&#xff0c;啥是ruby&#xff0c;不解释&#xff0c;因为开始我也不懂&#xff0c;就当他是命令行。 1&#xff…

基于Java的在线聊天APP系统分析及设计

基于Java的在线聊天APP系统分析及设计 目录 基于Java的在线聊天APP系统分析及设计 1 一、 需求分析 3 核心用户分析 3系统的主要功能的概述 3项目操作流程图 4功能详解 4 登录 4注册 4消息盒子 4好友盒子 4好友列表 4朋友验证 4我的账号 4新的朋友 5验证消息 5好友资料卡 5删…

Taro+react仿微信app聊天室|taro仿微信界面|taro聊天/朋友圈

基于TaroreactreduxRNtaroPop等技术开发的跨端聊天App实例&#xff0c;支持编译到多端H5小程序RN端&#xff0c;界面仿制微信聊天界面&#xff0c;实现了消息发送、表情、图片预览、长按菜单、红包、朋友圈等功能。 Taro三端统一聊天应用&#xff1a;taro-chatroom (仿微信界面…

android机器人聊天软件,虚拟男友聊天机器人

虚拟男友聊天机器人是一款能为大家提供专业的虚拟聊天软件&#xff0c;在这里大家可以设定一个符合自己心意的男友&#xff0c;让你们之间的对话是充满了甜蜜&#xff0c;并且还可以自己设定回复方式&#xff0c;对话也是十分的轻松愉悦&#xff0c;快来下载虚拟男友聊天机器人…

uniapp开发即时通讯聊天app,纯nvue仿微信,前后端开源

github地址&#xff1a;GitHub - guipie/GpChat: uniapp开发的纯nvue的即时聊天通讯App。 gitee&#xff1a;https://gitee.com/chenwei_zq/GpChat uniapp开发的纯nvue的即时聊天通讯App。 后台采用.net6,一套解决方案&#xff0c;分布式部署。 App采用uniapp的纯nvue&#x…

使用dialogflow和firebase构建whatsapp聊天机器人的指南

ChatBots are conversational agents, programs capable of conducting a conversation with an Internet user. In this tutorial I’ll walk you through an implementation of WhatsApp chatbot using Twilio platform. ChatBots是对话代理&#xff0c;是能够与Internet用户…

【uni-app】uni-app实现聊天页面功能(小程序)——布局篇

文章目录 前言划分区域问题内容溢出关于调试聊天框 代码实现 前言 在工作中使用uni-app参与开发一个小程序&#xff0c;其中要写一个简单的聊天页面&#xff0c;虽然功能不多&#xff08;只有一个发送文字的功能&#xff09;&#xff0c;但是其中的细节比较多&#xff0c;也踩…

如何搜索WhatsApp聊天消息

Trying to find a specific message in your huge WhatsApp chat log? There are two ways to search, so you can find what you’re looking for quickly. 试图在庞大的WhatsApp聊天日志中查找特定消息&#xff1f; 有两种搜索方式&#xff0c;因此您可以快速找到要查找的内…

【uni-app】uni-app实现聊天页面功能——功能篇(下)

目录 前言一、聊天框随键盘抬起思路代码实现 二、聊天消息列表随着聊天框的增高而滚动到最底部思路 三、问题完整代码实现总结 前言 前面我有写关于如何进行聊天页面布局和实现聊天消息滚动到最底部的文章。 【uni-app】uni-app实现聊天页面功能——功能篇&#xff08;上&…

如何将 WhatsApp 聊天添加到您的网站

WhatsApp是全球最受欢迎的消息传递应用程序。平台上有超过 2 亿活跃用户与朋友、家人和企业进行交流。对于企业而言&#xff0c;WhatsApp 是与客户进行个人、可访问和非正式对话的理想渠道。 要将 WhatsApp 作为渠道引入您的客户旅程&#xff0c;第一步是将 WhatsApp 聊天按钮…

uni-app 即时聊天

项目介绍 前段时间在B站看到了有一个UP主在讲uni-app即时聊天的项目&#xff08;逸刻时光&#xff09;&#xff0c;在看了这个视频之后&#xff0c;感觉还是挺有兴趣的&#xff0c;所以在看他的讲解视频之后&#xff0c;就自己动手写了这个即时聊天项目&#xff0c;在样式方面…

uniapp+nvue实现仿微信App聊天应用 —— 成功实现好友聊天+语音视频通话功能

基于uniapp nvue实现的uniapp仿微信App聊天应用 txim 实例项目&#xff0c;实现了以下功能。 1: 聊天会话管理 2: 好友列表 3: 文字、语音、视频、表情、位置等聊天消息收发 4: 一对一语音视频在线通话 技术实现 开发环境&#xff1a;HbuilderX nodejs技术框架&#xff…