温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

微信小程序用视图容器(swiper)组件创建轮播图的方法

发布时间:2020-06-23 09:55:07 来源:亿速云 阅读:176 作者:清晨 栏目:web开发

这篇文章将为大家详细讲解有关微信小程序用视图容器(swiper)组件创建轮播图的方法,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

一、视图容器(Swiper)

1、swiper:滑块视图容器

微信官方文档

微信小程序用视图容器(swiper)组件创建轮播图的方法

微信小程序用视图容器(swiper)组件创建轮播图的方法

二、swiper应用

1、页面逻辑(index.js)

Page({
 data: {
 imgUrls: [
 {
 link: '/pages/index/index',
 url: '/images/001.jpg'
 }, {
 link: '/pages/list/list',
 url: '/images/002.jpg'
 }, {
 link: '/pages/list/list',
 url: '/images/003.jpg'
 }
 ],
 indicatorDots: true, //小点
 indicatorColor: "white",//指示点颜色
 activeColor: "coral",//当前选中的指示点颜色
 autoplay: false, //是否自动轮播
 interval: 3000, //间隔时间
 duration: 3000, //滑动时间
 }

其中 imgUrls 是我们轮播图中将要用到的 图片地址和 跳转链接

    indicatgorDots 是否出现焦点

    autoplay 是否自动播放

    interval 自动播放间隔时间

    duration 滑动动画时间

2、页面结构(index.wxml)

<!--轮播图-->
<swiper indicator-dots="{{indicatorDots}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}" indicator-color="{{indicatorColor}}" 
 indicator-active-color="{{activeColor}}">
 <block wx:for="{{imgUrls}}">
 <swiper-item>
 <navigator url="{{item.link}}" hover-class="navigator-hover">
 <image src="{{item.url}}" class="slide-image" width="355" height="200" />
 </navigator>
 </swiper-item>
 </block>
</swiper>

注意:swiper 千万不要在外面  加上任何标签 例如 <view> 之类的 ,如果加了可能会导致轮播图出不来

3、页面样式(index.wxss)

/*轮播图*/
.slide-image {
 width: 100%;
}

三、小程序效果图

赶快动手实践就可以看到如图所示效果图:

微信小程序用视图容器(swiper)组件创建轮播图的方法

关于微信小程序用视图容器(swiper)组件创建轮播图的方法就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI