百度小程序-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 ...
随机推荐
- CSU 1553 Good subsequence(RMQ问题 + 二分)
题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1553 Description Give you a sequence of n nu ...
- ora4031
http://blog.itpub.net/23135684/viewspace-1203447/ Mon Sep 11 08:56:10 2017Errors in file /oracle/db/ ...
- machine learning 之 Recommender Systems
整理自Andrew Ng的machine learning 课程 week 9. 目录: Problem Formulation(问题的形式) Content Based Recommendation ...
- Python的Django框架中的URL配置与松耦合
Python的Django框架中的URL配置与松耦合 用 python 处理一个文本时,想要删除其中中某一行,常规的思路是先把文件读入内存,在内存中修改后再写入源文件. 但如果要处理一个很大的文本,比 ...
- Spring cloud学习--Zuul01
Zuul解决的问题 作为系统的统一入口,屏蔽了系统内部各个微服务的细节 可以与微服务治理框架结合,实现自动化的服务实例维护以及负载均衡的路由转发 实现接口权限校验与微服务业务逻辑的解耦 搭建Zuul服 ...
- vue 全局filter的坑
下面连段代码的filter放在不同的位子会有不同的效果, 1.filter放在new vue之后,居然不起作用 <script> new Vue({ el: '#app', data: { ...
- [HDU 1529]Cashier Employment(差分约束系统)
[HDU 1529]Cashier Employment(差分约束系统) 题面 有一个超市,在24小时对员工都有一定需求量,表示为\(r_i\),意思为在i这个时间至少要有i个员工,现在有n个员工来应 ...
- vmware linux root密码破解
centOS: 1.开机过程按上下箭头键,让系统不要进入到引导程序中, 2.按 'e' 进入到编辑模式 3.找到linux16开始的首行,在末尾加入'rw init=/bin/sh' (会出现修改密码 ...
- Tensorflow机器学习入门——MINIST数据集识别
参考网站:http://www.tensorfly.cn/tfdoc/tutorials/mnist_beginners.html #自动下载并加载数据 from tensorflow.example ...
- .net 异步
原文:https://www.cnblogs.com/wisdomqq/archive/2012/03/26/2412349.html 在说到异步前,先来理一下几个容易混淆的概念,并行.多线程.异步. ...