官网地址:https://developers.weixin.qq.com/miniprogram/dev/component/swiper.html

index.wxml文件

indicator-dots:是否显示面板指示点
autoplay:是否自动切换
interval:自动切换时间间隔
circular:是否采用衔接滑动
duration:滑动动画时长

更多属性请查看官网
 <swiper indicator-dots="{{indicatorDots}}" autoplay="{{autoplay}}" interval="{{interval}}" circular="{{circular}}" duration="{{duration}}" class='hlzbsp'>
<block wx:for="{{phonelist}}" wx:for-item="item" wx:for-index="idx">
<swiper-item>
<image src="{{item.phoneurl}}" style='position: absolute;width:{{item.phoneWidth}}rpx; height:{{item.phoneheight}}rpx; top:{{item.top}}rpx; left: {{item.left}} rpx;' mode="aspectFit"></image>
</swiper-item>
</block>
</swiper>

mode:图片缩放方式,如果不设置改属性,样式可能失效

mode相关属性官网:https://developers.weixin.qq.com/miniprogram/dev/component/image.html

index.js文件

const app = getApp()
Page({
  data: {
phonelist:[], //轮播图片列表
indicatorDots: true,//是否显示面板指示点
autoplay: true,//是否自动切换
circular:true,//是否采用衔接滑动
interval: 3000,//自动切换时间间隔
duration: 1000,//滑动动画时长
}, phone:function(){
//这里采用动态获取照片
wx.request({
url: '后台访问地址',
header: {
//设置参数内容类型为x-www-form-urlencoded
'content-type': 'application/x-www-form-urlencoded'
},
method: 'GET',
success: function (res) {
var list=[];//定义临时数组
var phonecomment={};//定义临时对象
//res.data.data.lsit是从后台拿到的数据,可根据后台传参获取 格式:[{id:1,photoDetails:aaa.jsp},{id:2,photoDetails:bbb.jsp},{id:3,photoDetails:ccc.jsp}]
if (res.data.data.lsit.length>0){
for (var i = 0; i < res.data.data.lsit.length; i++) {
phonecomment={};//将临时对象赋值空
phonecomment.phoneurl = res.data.data.lsit[i].photoDetails;//保存图片地址
       //官方接口 获取图片信息
wx.getImageInfo({
src: res.data.data.lsit[i].photoDetails,//图片地址
success: function (phone) {
var originalWidth = phone.width;//返回该图片的宽
var originalHeight = phone.height;//返回该图片的高 var minwidth =670 /originalWidth;//670为轮播框的宽,670/originalWidth 是轮播框宽与图片宽比例
var minheight = 380 / originalHeight;//380为轮播框的高 380/originalHeight 是轮播框高与图片高比例
if (minwidth >= minheight){
phonecomment.phoneheight = originalHeight * minheight;//图片需要设置的高
phonecomment.phoneWidth = originalWidth * minheight;//图片需要设置的宽
phonecomment.top = (380 - originalHeight * minheight) / 2;//图片距离轮播框顶部的距离
phonecomment.left = (670 - originalWidth * minheight) / 2;//图片距离轮播框左边的距离
//phonecomment.top phonecomment.left作用:图片居中
}else{
phonecomment.phoneheight = originalHeight * minwidth;
phonecomment.phoneWidth =originalWidth * minwidth;
phonecomment.top = (380 - originalHeight * minwidth) / 2;
phonecomment.left=(670 - originalWidth * minwidth) / 2;
}
},
fail: function (res) {
console.log("获取图片高宽失败");
},
})
list.push(phonecomment);//将临时对象存放到临时数组中 }
console.log(list);
that.setData({
phonelist: list //赋值
}); console.log(list);
}else{
console.log("暂无轮播图片");
} }
}) } })

微信小程序轮播图组件 swiper,swiper-item及轮播图片自适应的更多相关文章

  1. 图解微信小程序---添加tabBar底部菜单,添加已做好轮播图操作

    图解微信小程序---添加tabBar底部菜单,添加已做好轮播图操作 什么是tabBar? 顶部或者底部tab栏如果小程序是一个多 tab 应用(客户端窗口的底部或顶部有 tab 栏可以切换页面),可以 ...

  2. reactjs-swiper react轮播图组件基于swiper

    react轮播图组件基于swiper demo地址:http://reactjs-ui.github.io/reactjs-swiper/simple.html 1. 下载安装 npm install ...

  3. [小程序开发] 微信小程序audio音频播放组件+api_wx.createAudioContext

    引言: audio是微信小程序中的音频组件,可以轻松实现小程序中播放/停止音频等自定义动作. 附上微信小程序audio组件的相关属性说明:https://mp.weixin.qq.com/debug/ ...

  4. 微信小程序中-折线图

    echarts配置项太多了,还是一点点积累吧~~~~~ 当然前提条件还是得老老实实看echarts官方文档 :https://echarts.baidu.com/ 今天主要就介绍下我在工作中通过ech ...

  5. 微信小程序绘制分享图

    微信小程序绘制分享图例子: demo下载地址:https://gitee.com/v-Xie/wxCanvasShar 大致代码会再以下说明 实际开发项目: 基础知识点: 了解canvas基础知识 w ...

  6. 微信小程序页面调用自定义组件内的事件

    微信小程序页面调用自定义组件内的事件 page page.json { "usingComponents": { "my-component": ". ...

  7. 微信小程序(二十)-UI组件(Vant Weapp)-01按装配置

    1.官网 https://vant-contrib.gitee.io/vant-weapp/#/intro https://gitee.com/vant-contrib/vant-weapp 2.按装 ...

  8. 微信小程序 基本介绍及组件

    创建项目 微信开发工具深入介绍 https://developers.weixin.qq.com/miniprogram/dev/devtools/devtools.html 基本项目目录 1. 配置 ...

  9. 微信小程序开发—快速掌握组件及API的方法

    微信小程序框架为开发者提供了一系列的组件和API接口. 组件主要完成小程序的视图部分,例如文字.图片显示.API主要完成逻辑功能,例如网络请求.数据存储.音视频播放控制,以及微信开放的微信登录.微信支 ...

  10. 微信小程序开发—快速掌握组件及API的方法---转载

    微信小程序框架为开发者提供了一系列的组件和API接口. 组件主要完成小程序的视图部分,例如文字.图片显示.API主要完成逻辑功能,例如网络请求.数据存储.音视频播放控制,以及微信开放的微信登录.微信支 ...

随机推荐

  1. vs 快捷操作

    1.   选中所需行 增加缩进 tab 减少缩进 shift+tab 2.附加调试:ctrl+alt+p: 全部用快捷键操作看起来真的很6

  2. VS2012遇到一个问题:"链接器工具错误 LNK2026 XXX模块对于 SAFESEH 映像是不安全的"

    解决方法: 1.打开该项目的“属性页”对话框. 2.单击“链接器”文件夹. 3.单击“命令行”属性页. 4.将 /SAFESEH:NO 键入“附加选项”框中,然后点击应用.

  3. 【原创】大数据基础之Zookeeper(1)介绍、安装及使用

    zookeeper3.4.11 http://zookeeper.apache.org/ 一 简介 ZooKeeper is a centralized service for maintaining ...

  4. js通过高德地图获取当前位置的经度纬度

    效果图如下: 已经获取到了经度纬度了 代码如下: <!doctype html> <html> <head> <meta charset="utf- ...

  5. Intsall The Nessus in you kali linux

    1.first you shold download the nessus on the web station the nessus download site url:  https://www. ...

  6. 3.RNN推导

    1.基本RNN结构 这几天想入门NLP,所以开始了解RNN以及一系列变体.首先RNN最原始的结构如下图(图是按自己的理解用visio画的,有错麻烦提一下), 首先我们来说明一下各个符号的定义: 各个变 ...

  7. es6中的...三个点

    ...是es6中新添加的操作符,可以称为spread或rest 定义一个数组 let name=['小红','小明','小白']; 我们在控制台输出   console.log(name); 结果: ...

  8. Python基础——切片实例

    切片实例 L = list(range(100)) print(L, end=' ') [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1 ...

  9. 潭州课堂25班:Ph201805201 tornado 项目 第七课 界面美化和静态文件处理(课堂笔记)

    tornado 相关说明 使用  Bootstrap 前端框架 可以在 bootCDN 这里找 jquery ,poppe.js 文件 美化项目 twittel 的开源项目, 在 static 目录下 ...

  10. BZOJ 5118

    矩阵乘也是可以欧拉定理的HHH 所以幂次就是$(2^n-1) ~ mod ~ \varphi(p)$就好了 const ll p=1125899839733759ll; inline ll mu(ll ...