百度小程序-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 ...
随机推荐
- 关于Spring中BeanUtils的一次使用问题记录
1.问题描述:今天在进行前后端联调的时候,发现商品图片不能正常显示: 2.排查过程:查看浏览器控制台,发现调用接口返回的数据关于图片的字段未返回数据: 然后,又跑了一下Dao层的单元测试,从 ...
- R python在无图形用户界面时保存图片
在用python的matplotlib,和R中自带的作图,如果想保存图片时,当你有图形用户界面时是没有问题的,但是当没有图形用户界面时,会报错: 在R中,解决办法: https://blog.csdn ...
- 匿名函数 sorted() filter() map() 递归函数
一. lambda() 匿名函数 说白了,从字面理解匿名函数就是看不见的函数,那么他的看不见表现在哪里呢? 其实就是在查询的时候他们的类型都是lambda的类型所以叫匿名,只要是用匿名函数写的大家 ...
- Visual Studio Code-使用Chrome Debugging for VS Code调试JS
准备工作 安装 Debugger for Chrome 插件 按 F5(或选择菜单栏的 Debug->Start Debuging),然后选择 Chrome,就会自动创建默认的配置文件 &quo ...
- windows mysql官方绿色版zip包安装教程
环境: 系统环境 Windows 10 64位 mysql版本 5.7.19 一.万变不离的下载 下载页面:https://dev.mysql.com/downloads/mysql/ 点击 Down ...
- Harbor - 私有企业级 Docker 镜像仓库
GitHub 地址 容器镜像服务 Docker镜像的基本使用 Docker:企业级私有镜像仓库Harbor使用 Harbor 是基于 Docker Registry 的企业级镜像仓库,安装后的使用方法 ...
- 【ABAP系列】SAP ABAP基础-录制BDC的MODE定义解析
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP基础-录制BDC ...
- 个人珍藏的PC和安卓应用列表
个人珍藏的PC和安卓应用列表 PC应用名称 功能描述 注意事项 存储位置 维棠FLV视频下载软件 可用来下载腾讯视频的视频 将视频列表的网址粘贴到维棠软件左侧"下载"的地址中即可批 ...
- 数据库学习之mysql数据库
参考链接网站: http://c.biancheng.net/view/2361.html Mysql的版本以及版本号 MySQL Community Server(社区版):该版本完全免费,但是官方 ...
- python args参数理解
文件名:while.py 代码:import sysprint(sys.path)print(sys.argv) 执行结果: ['D:\\python_basic\\s01', 'D:\\python ...