微信小程序> 微信小程序实现瀑布流

微信小程序实现瀑布流

浏览量:603 时间: 来源:小Q飞

CSS3 多列实现

  • column-count  定义几列
  • column-gap   列间距  

wxml的布局  

view class='content'  block wx:for="{{dataArray}}" wx:key=""     template is="item" data="{{...item}}"/template  /block  /view
template name="item"  view class='item'    image class="image" src="{{url+'?imageView2/0/w/500'}}"  data-src="{{url}}" bindtap="previewImage" mode="widthFix"/image    view class='item-text-view'        text class='time-text'{{who}}/text    /view  /view/template

样式代码wxss

.image {  width: 100%;   margin:0 auto;}.time-text{  font-size: 14px;  color: #fff;}.item-text-view{  background: #000000;  height: 30px;  position: relative;  margin-top: -35px;  display: block;  opacity: 0.6}.content{  margin: 0.5%;  column-count: 2;  column-gap: 0px;}.item{  width: 98%;  height: auto;  text-align: center;  margin-left:  0.5%;  margin-right: 0.5%;  margin-bottom: 0.5%;  display: inline-block;  border:1px solid #ccc;}

这样就实现了瀑布流 。

小程序

这样完了么 (如果你只有一页数据你可以无视后面的内容),你会发现如果是一个长列表数据。  随着数据不断添加 ,右边会出现闪烁,图片位置在不断的变化,显然这不是咱要的瀑布流。

下来不要用css3的样式就分列了 我们自己手动去分列。

和css3实现代码差不多  就是多了一些判断分列!

wxml的布局  

view class='content'  view class="item-view"    block wx:for="{{dataArray}}" wx:key=""      template is="item" data="{{...item}}" wx:if="{{index%2==0}}"/template    /block  /view  view class="item-view"    block wx:for="{{dataArray}}" wx:key=""      template is="item" data="{{...item}}" wx:if="{{index%2==1}}"/template    /block  /view/view

这个方法是网上找到的办法 微信小程序 瀑布流布局

.image {  width: 100%;   margin:0 auto;}.time-text{  font-size: 14px;  color: #fff;}.item-text-view{  background: #000000;  height: 30px;  position: relative;  margin-top: -35px;  display: block;  opacity: 0.6}.content{  margin: 0.5%;}.item{  width: 98%;  height: auto;  text-align: center;  margin-left:  0.5%;  margin-right: 0.5%;  margin-bottom: 0.5%;  display: inline-block;  border:1px solid #ccc;}

最重要的样式就是没列的宽度不超过50%要就到下面去了 就不是两列了。

.item-view{   width: 50%;   float: left;}

到这里就实现了瀑布流。

小程序

css3实现的每个item的顺序其实都不是想要的,仔细看会发现的。

接口来自: 干货集中营

版权声明

即速应用倡导尊重与保护知识产权。如发现本站文章存在版权问题,烦请提供版权疑问、身份证明、版权证明、联系方式等发邮件至197452366@qq.com ,我们将及时处理。本站文章仅作分享交流用途,作者观点不等同于即速应用观点。用户与作者的任何交易与本站无关,请知悉。

产品经理

手机 : 13312967497

擅长 : 小程序流量变现

扫码领取礼包

热门模板

  • 头条
  • 搜狐
  • 微博
  • 百家
  • 一点资讯
  • 知乎