百度小程序-swiper组件
.swan
<!-- 轮播图S -->
<view class="swiper-box">
<swiper class="banner" style='height:{{swiperH}}' bindchange="swiperChange" autoplay="true" interval="3000" duration="500"
circular="true">
<block s-for="banner" s-for-index="index" s-for-item="item">
<swiper-item>
<image src="{{item.cover_id}}" class="slide-image" mode="widthFix" bindload='imgHeight' />
</swiper-item>
</block>
</swiper>
<view class="dots">
<block s-for="banner" s-for-index="index" s-for-item="item">
<view class="dot {{index == swiperCurrent ? 'active' : ''}}"></view>
</block>
</view>
</view>
<!-- 轮播图E -->
.css
/* 轮播图 S*/
.slide-image{width: 100%;}
/* 圆点样式控制 S*/
.swiper-box{position: relative; width: 100%;}
.dots{position: absolute; left:; right:; bottom:; display: -webkit-box; display: -webkit-flex; display: -moz-box; display: -ms-flexbox; display: flex; -webkit-box-pack: center; -webkit-justify-content: center; -moz-box-pack: center; -ms-flex-pack: center; justify-content: center; padding: 10rpx 0; background: rgba(0, 0, 0, .2)}
.dots .dot{margin: 0 8rpx; width: 14rpx; height: 14rpx; background: rgba(255,255,255,.8); border-radius: 8rpx; -webkit-transition: all .6s; transition: all .6s;}
.dots .dot.active{width: 40rpx; background: #ef782c;}
/* 圆点样式控制 E*/
/* 轮播图 E*/
.js
const app = getApp();
Page({
data: {
banner: [],//轮播图
swiperCurrent: "",//轮播图圆点
swiperH: "", //这是swiper框要动态设置的高度属性
},
onLoad: function () {
// 监听页面加载的生命周期函数
this.getBanner();
},
onReady: function() {
// 监听页面初次渲染完成的生命周期函数
},
onShow: function() {
// 监听页面显示的生命周期函数
app.setInfo();
},
onHide: function() {
// 监听页面隐藏的生命周期函数
},
onUnload: function() {
// 监听页面卸载的生命周期函数
},
onPullDownRefresh: function() {
// 监听用户下拉动作
},
onReachBottom: function() {
// 页面上拉触底事件的处理函数
},
onShareAppMessage: function () {
// 用户点击右上角转发
},
swiperChange: function (e) {
this.setData({
swiperCurrent: e.detail.current //获取当前轮播图片的下标
})
},
imgHeight: function (e) {
var winWid = swan.getSystemInfoSync().screenWidth;
var imgh = e.detail.height;//图片高度
var imgw = e.detail.width;//图片宽度
var swiperH = winWid * imgh / imgw + "px";
//等比设置swiper的高度。 即 屏幕宽度 / swiper高度 = 图片宽度 / 图片高度 ==》swiper高度 = 屏幕宽度 * 图片高度 / 图片宽度
this.setData({
swiperH: swiperH//设置高度
});
},
getBanner: function () {//获取banner轮播图
var that = this;
swan.request({
url: app.globalData.baseUrl + 'list/banner',
method: 'GET',
header: {
genToken: app.globalData.genToken,
},
success: function (res) {
// console.log(res);
that.setData({
banner: res.data.lines
})
// console.log(that.data.banner)
}
});
}
});
效果图

百度小程序-swiper组件的更多相关文章
- 百度小程序-map组件定位
给客户开发一个百度小程序,有个地图定位显示.百度小程序内置的api地图是不准的,通过百度一下,查询到坐标偏移算法公式,自己项目中使用,手机测试坐标已经正常显示! 经纬度,通过百度坐标拾取器拾取到! . ...
- 基于angular实现模拟微信小程序swiper组件
这段时间的主业是完成一个家政类小程序,终于是过审核发布了.不得不说微信的这个小程序生态还是颇有想法的,抛开他现有的一些问题不说,其提供的组件系统乍一看还是蛮酷的.比如其提供的一个叫swiper的视图组 ...
- 小程序swiper组件高度自适应【转载】
最近在做小程序开发,复制官方文档上的swiper组件实测后发现,图片不能自适应.网上找了几个版本测试都发现存在一些小问题,目前这个版本本人实测是最好用的.记录一下,方便日后使用. 感谢原创大神的帮助, ...
- 跳坑 小程序swiper组件 轮播图片 右边空白问题
swiper 组件 设置轮播图片时,右侧会出现空白的情况:是因为 swiper组件有默认的 高度和宽度,所以我们在设置图片高度和宽度的同时, 也要为 设置高度和宽度,和高度和宽度样式一样的就可以.
- 微信小程序 swiper 组件坑
swiper 组件高度被限制为150px了,所以内容无法撑开. 解决办法 给这组件重新设置个高度,然后在把里面的图片设置为自动适应容器大小.图片模式设置为 宽度不变 自动适应高度 <swiper ...
- 小程序swiper组件的bindchange方法重复执行问题
这是官方文档的说法给出了swiper组件一直来回滑动的bug原因 以下是修正方法 <swiper autoplay="{{autoplay}}" interval=" ...
- 微信小程序--swiper组件
<view class='swiper-container'> <swiper indicator-dots="true" autoplay=" ver ...
- 第五篇、微信小程序-swiper组件
常用属性: 效果图: swiper.wxml添加代码: <swiper indicator-dots="{{indicatorDots}}" autoplay="{ ...
- 微信小程序swiper组件实现图片宽度自适应
wxml 代码: <!--pages/swipe/swipe.wxml--> <view> <swiper circular="true" indic ...
随机推荐
- 如何把vue.js项目部署到服务器上
如何把vue.js项目部署到服务器上面,我用的是tomcat服务器 1-改一下config/index.js文件,如下图,把assetsPublicPath: './', productionSour ...
- 2018-2019-2 20175307 实验四《Android程序设计》实验报告
任务一 实验要求和内容: Android Stuidio的安装测试: 参考<Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)>第二十 ...
- C++ lower_bound 与 upper_bound 函数
头文件: #include <algorithm> 二分查找的函数有 3 个: 参考:C++ lower_bound 和upper_bound lower_bound(起始地址,结束地址 ...
- Delphi 文件转换Base64
uses EncdDecd; function FileToBase64(FileName: string): string; var MemoryStream: TMemoryStream;beg ...
- Vue过渡:CSS过渡
一 项目结构 二 App.vue <template> <div id="app"> <transition name="fade" ...
- 类型(type)判断
windows下源文件编码问题 在windows下不要直接右击桌面创建.txt再改成.c,这种方式容易引起编码问题 windows下gvim的设置: 先打开gvim再用:w newfile.c这种方式 ...
- Win7 VS2019安装后创建C++工程失败解决
VS2019正式上手,第1个问题创建不了工程,看起来非常类似之前VS2017更新 解决办法 https://github.com/Microsoft/msbuild/issues/4286 和上次的问 ...
- Node.js实战4:标准IO及console对像。
IO即输入输出. console用于Nodejs程序信息输出. Nodejs的IO操作,通过process.stdout.process.stdin来操作. 下面的例子,将简单展示这两个函数的用法.程 ...
- python的前景
最近几年Python编程语言在国内引起不小的轰动,有超越Java之势,本来在美国这个编程语言就是最火的,应用的非常非常的广泛,而Python的整体语言难度来讲又比Java简单的很多.尤其是在运维的应用 ...
- Windows组决策
https://blog.csdn.net/wangjunjun2008/article/details/82426587