小程序图片两列显示

效果图

 

问题描述

我的想法是将屏幕分为左右两个view,每个view循环一个list。整体flex布局,flex-direction: column就可以了。

代码

xml

<view class='cateCommodity '>
  <view class='item-container'>
    <block wx:for="{{leftitems}}" wx:key="{{item}}">
      <view style='width:{{screenWidth}}px;height:{{item.width}}px;' class='back-img'>
        <image src="{{item.url}}" style='width:{{screenWidth}}px;height:{{item.width}}px;' mode="scaleToFill" bindtap='showVideoInfo' data-arrindex='{{index}}'></image>
      </view>


      <view class="desc">
        <view class="faceName">
          <image class='myface' src="{{item.url}}"></image>
        </view>
      </view>
    </block>
  </view>

  <view class="item-container2">
    <block wx:for="{{rightitems}}" wx:key="{{item}}">
      <view style='width:{{screenWidth}}px;height:{{item.width}}px;' class='back-img'>
        <image src="{{item.url}}" style='width:{{screenWidth}}px;height:{{item.width}}px;' mode="scaleToFill" bindtap='showVideoInfo' data-arrindex='{{index}}'></image>
      </view>


      <view class="desc">
        <view class="faceName">
          <image class='myface' src="{{item.url}}"></image>
        </view>
      </view>
    </block>
  </view>

</view>

css

.cateCommodity {
  display: flex;
}


.item-container {
    position: relative;
    margin-left: 1px;
    flex-direction: column;
    display: flex;
}

.item-container2 {
    display: flex;
    position: relative;
    margin-left: 1px;
    flex-direction: column;
}

.cover {
    width: 100%;
    height: 400rpx;
    display: block; 
}

.back-img{
    display: block; 
    background-color: black;
    width: 50px;
}

.desc {
    margin-top: -40rpx;
    margin-bottom: 10rpx;
    display: flex;
    align-items: center;
}

.desc .right {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.desc .faceName {
    display: flex;
    flex-direction: column;
    align-items: center;
    
    margin-left: 10px;
}

.title {
    font-size: 30rpx;
    margin-top: 10rpx;
    margin-left: 20rpx;
    width: 600rpx;
}

.myface {
    display: block;
    width: 60rpx;
    height: 60rpx;
    border-radius: 30rpx;
    margin-top: 10rpx;
    margin-right: 20rpx;
}

.nickname {
    font-size: 20rpx;
    margin-top: 6rpx;
    margin-right: 20rpx;
    color: darkgray;
}

 

js

Page({
  data: {
    screenWidth: 350,
    leftitems: [
      {
        "url": "http://127.0.0.1:8081/190523GC92NGTD8H/face/tmp_646734b45590904e90efd541bef64fa8.jpg",
        "width":"250"
       },
      {
        "url": "http://127.0.0.1:8081/190522FM0FBTP0M8/face/tmp_eaea68152e18f8f53b26c36f9525e8b2.jpg",
        "width": "300"
      }

    ],
    rightitems: [
      {
        "url": "http://127.0.0.1:8081/190522F3CXKG14ZC/face/wx541e77df48cf8946.o6zAJs53iDBLVzTSAz8y2-KYzCdE.3Yy3aQ4GBVQHe9bee6d749b8ede59273d73b3fb46e1b.jpg",
        "width": "50"
      },
      {
        "url": "http://127.0.0.1:8081/190522FM0FBTP0M8/face/tmp_eaea68152e18f8f53b26c36f9525e8b2.jpg",
        "width": "300"
      }
      ]


  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var screenWidth = wx.getSystemInfoSync().screenWidth;
    this.setData({
      screenWidth: screenWidth / 2-1.5,
    });
  }

  
})

 

 

 

 

 

 

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值