加载中 ...
首页 > 新闻资讯 > 小程序 正文

小程序如何制作产品列表流布局

2019-07-31 09:12:09 来源:沈阳小程序开发 作者:沈阳软件开发

在许多商场小程序中,常规产品列表以流布局显示。以下是如何为小程序创建产品列表的简化布局?

21708-1PF4161344b3.jpg

流式布局概念流式布局也叫百分比布局把元素的宽,高,margin,padding不再用固定数值,改用百分比,这样元素的宽,高,margin,padding会根据页面的尺寸随时调整已达到适应当前页面的目的.

首先看一下效果:500

如上图所示,为了更直观地看,我为布局设置了一个红色虚线边框,整个页面根据元素的百分比进行布局。直接查看代码:

xxx.wxml {{item.name}}

¥{{item.newprice}}

¥{{item.oldprice}}

{{item.discount}}折叠

{{item.name}}

¥{{item.newprice}}

¥{{item.oldprice}}

{{item.discount}}折叠

通过查看类标记,我发现有两个img_item,所以我采用了分别加载数据的方法。

xxx.jsPage({ data: { scrollH: 0, imgWidth: 0, loadingCount: 0, images: [], col1: [], col2: [] }, onLoad: function () { wx.getSystemInfo({ success: (res) => { let ww = res.windowWidth; let wh = res.windowHeight; let imgWidth = ww * 0.48; let scrollH = wh; this.setData({ scrollH: scrollH, imgWidth: imgWidth }); //加载首组图片 this.loadImages(); } }) }, onImageLoad: function (e) { let imageId = e.currentTarget.id; let oImgW = e.detail.width; //图片原始宽度 let oImgH = e.detail.height; //图片原始高度 let imgWidth = this.data.imgWidth; //图片设置的宽度 let scale = imgWidth / oImgW; //比例计算 let imgHeight = oImgH * scale; //自适应高度 let images = this.data.images; let imageObj = null; for (let i = 0; i < images.length; i++) { let img = images[i]; if (img.id === imageId) { imageObj = img; break; } } imageObj.height = imgHeight; let loadingCount = this.data.loadingCount - 1; let col1 = this.data.col1; let col2 = this.data.col2; //判断当前图片添加到左列还是右列 if (col1.length <=>

以下代码:** if(col1.length&lt;=col2.length){col1.push(imageObj);} else {col2.push(imageObj);} **根据高度将项集合检索为两组。

xxx.wxsspage{ height: 100%; background-color: #F3F4F6;} /* 单个图片容器的样式 */.img_item { width: 48.5%; margin: 2px; display: inline-block; vertical-align: top; background-color: #ffffff; font-size: 24rpx;}.item_info{ border-top:1px dashed red;}.product-name{ color: #000; /* height: 28px; */ text-align:left; margin: 0px 5px; margin-bottom: 5px; }.product-price-wrap .product-price-new{ color: #e80080; margin-left:5px; font-weight:900;}.product-price-wrap .product-price-old{ color: #888; text-decoration: line-through; padding-left: 2px;}.product-price-wrap .discount{ margin-left: 30px; background-color: #000; color: #fff;}

HiShop小程序工具提供多种类型的商城/商店小程序制作,可视化编辑1秒,在线生成5个步骤。通过拖动和拼接模块布局小程序商城页面,你可以看到你得到的东西,你只需要艺术家来制作一个漂亮的商场。有关更多小程序商店,请参阅:小程序商店

&lt; 汇海(www.hvihi.com)是国内知名的商城系统和商城网站建设提供商,其中汇海技术小程序系统提供小程序商城开发,小程序配送系统,微分配系统,商城系统,电子商务网站建设, 微信发行系统,小程序商城及其他多端商场和电子商务行业解决方案&gt;

确认:这个文件和图像源网络编辑器的网站部分,如果有侵权及时通信删除。 汇海hvihi.com网站原创文章,请注明出处。

“沈阳软件公司”的新闻页面文章、图片、音频、视频等稿件均为自媒体人、第三方机构发布或转载。如稿件涉及版权等问题,请与

我们联系删除或处理,客服QQ:55506560,稿件内容仅为传递更多信息之目的,不代表本网观点,亦不代表本网站赞同

其观点或证实其内容的真实性。