CSS3實現微信小程序瀑布流佈局

參考:做者:阿峯web

連接:https://www.jianshu.com/p/14d4b9ac473c
 來源:簡書

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 屬性。xss

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

微信小程序瀑布流佈局

瀑布流

wxmlide

<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%;
}

JSurl

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'
      }
    ]
  }
})
相關文章
相關標籤/搜索