首页 > 技术文章 > 微信小程序css瀑布流布局(仅做参考,css布局只会先渲染列,这种瀑布流并不实用)

Glant 2019-08-12 10:25 原文

wxml

<view class='case-page'>
  <view class='list-masonry'>
    <view class='item-masonry' wx:for="{{note}}">
      <image class="play" src='/images/news/play.png'></image>
      <view class="item-content">
        <image class="videoimg" src='{{item.url}}' mode='widthFix'></image>
        <text>下载</text>
      </view>
    </view>
  </view>
</view>

wxss

.case-page {
  padding: 10rpx 15rpx 30rpx;
}

.list-masonry {
  column-count: 2;
  column-gap: 10rpx;
}

.item-masonry {
  background-color: #fff;
  break-inside: avoid;
  box-sizing: border-box;
  padding: 5rpx;
  position: relative;
}

.play {
  width: 48rpx;
  height: 48rpx;
  z-index: 100;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.videoimg {
  width: 100%;
  border-radius: 18rpx;
}
.item-content{
  position: relative;
}
.item-content text {
  width: 80rpx;
  height: 30rpx;
  text-align: center;
  line-height: 30rpx;
  font-size: 20rpx;
  color: #fff;
  border: 2rpx solid #fff;
  box-sizing: border-box;
  border-radius: 6rpx;
  position: absolute;
  right: 20rpx;
  bottom: 30rpx;
}

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'
      }
    ]
  }
})

 

推荐阅读