CSS3实现微信小程序瀑布流布局的代码示例

2020-07-23 11:03:05
本篇文章给大家带来的内容是关于CSS3实现微信小程序瀑布流布局的代码示例,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

1.column-count 属性规定元素应该被分隔的列数:

-moz-column-count:3;     /* Firefox */-webkit-column-count:3; /* Safari 和 Chrome */column-count:3;

2.column-gap 属性规定列之间的间隔:

-moz-column-gap:40px;        /* Firefox */-webkit-column-gap:40px;    /* Safari 和 Chrome */column-gap:40px;

3.column-rule 属性设置列之间的宽度、样式和颜色规则。

-moz-column-rule:3px outset #ff0000;    /* Firefox */-webkit-column-rule:3px outset #ff0000;    /* Safari and Chrome */column-rule:3px outset #ff0000;

4.column-span 属性规定元素应横跨多少列。
Internet Explorer 10 和 Opera 支持 column-span 属性。
Safari 和 Chrome 支持替代的 -webkit-column-span 属性。
/只有 Chrome 和 Opera 支持 column-span 属性。/

-webkit-column-span:all; /* Chrome */column-span:all;

5.column-width 属性规定列的宽度。
Internet Explorer 10 和 Opera 支持 column-width 属性。
Firefox 支持替代的 -moz-column-width 属性。
Safari 和 Chrome 支持替代的 -webkit-column-width 属性。
注释:Internet Explorer 9 以及更早版本的浏览器不支持 column-width 属性。

column-width:100px;-moz-column-width:100px; /* Firefox */-webkit-column-width:100px; /* Safari 和 Chrome */

微信小程序瀑布流布局

wxml

<view class='case-page'>  <view class='list-masonry'>    <view class='item-masonry' wx:for="{{note}}">      <image src='{{item.url}}' mode='widthFix'></image>      <text>{{item.title}}</text>    </view>  </view></view>

wxss

page{  background-color: #eee;}.case-page{  padding:20rpx;}.list-masonry{  column-count: 2;  column-gap: 20rpx;}.item-masonry{  background-color: #fff;  break-inside: avoid;/*避免在元素内部插入分页符*/  box-sizing: border-box;   padding: 20rpx;  margin-bottom:20rpx;}.item-masonry image {  width: 100%;}

JS

Page({  /**   * 页面的初始数据   */  data: {    imgWidth: 0, imgHeight: 0,    note: [      {        title: '案例名称',        url: 'http://zq.jhcms.cn/attachs/photo/201711/20171130_176CFE51B6710715B1BBBEF2F86ACB0C.jpg',      },      {        title: '你所不知道的红酒知识',        url: 'http://img3.imgtn.bdimg.com/it/u=1417732605,3777474040&fm=26&gp=0.jpg',      },      {        title: '红酒知识',        url: 'http://f10.baidu.com/it/u=121654667,1482133440&fm=72',      },      {        title: '案例名称',        url: 'http://zq.jhcms.cn/attachs/photo/201711/20171130_9E39DA252E3946BE36218D85876C4AB4.jpg',      },      {        title: '案例名称',        url: 'http://img3.imgtn.bdimg.com/it/u=1417732605,3777474040&fm=26&gp=0.jpg'      },      {        title: '案例名称',        url: 'http://f10.baidu.com/it/u=121654667,1482133440&fm=72'      },      {        title: '案例名称',        url: 'http://img4.imgtn.bdimg.com/it/u=2748975304,2710656664&fm=26&gp=0.jpg'      },      {        title: '案例名称',        url: 'http://img2.imgtn.bdimg.com/it/u=1561660534,130168102&fm=26&gp=0.jpg'      },      {        title: '案例名称',        url: 'http://img3.imgtn.bdimg.com/it/u=1417732605,3777474040&fm=26&gp=0.jpg'      }    ]  }})