初识微信小程序之swiper和swiper-item的基本使用

在我还没接触到微信小程序之前,通常使用轮播要么手写或使用swiper插件去实现,当我接触到微信小程序之后,我看到了微信小程序的强大之处,让我为大家介绍一下吧!

swiper与swiper-item一起使用可以做轮播图

基本使用,上代码:

html 复制代码
<swiper class="swiper-container">
  <swiper-item>
    <view class="item">A</view>
  </swiper-item>
  <swiper-item>
    <view class="item">B</view>
  </swiper-item>
  <swiper-item>
    <view class="item">C</view>
  </swiper-item>
</swiper>

样式

css 复制代码
.swiper-container {
  height: 150px;
}
.item{
  height: 100%;
  text-align: center;
  line-height: 150px;
}
swiper-item:nth-child(1) .item{
  background-color: pink;
}
swiper-item:nth-child(2) .item{
  background-color: red;
}
swiper-item:nth-child(3) .item{
  background-color: gold;
}

swiper当中常用的属性

属性 类型 默认值 说明
indicator-dots boolean false 是否显示面板指示点
indicator-color color rgba(0, 0, 0,.3) 指示点颜色
indicator-active-color color false 当前选中的指示点颜色
autoplay boolean false 是否自动切换
interval number 5000 自动切换时间间隔
circular boolean false 是否采用衔接滑动
html 复制代码
<!-- 属性 indicator-dots -->
<swiper class="swiper-container" indicator-dots indicator-color="#fff" indicator-active-color="red" autoplay interval="2000" circular>
  <swiper-item>
    <view class="item">A</view>
  </swiper-item>
  <swiper-item>
    <view class="item">B</view>
  </swiper-item>
  <swiper-item>
    <view class="item">C</view>
  </swiper-item>
</swiper>

学如逆水行舟,不进则退,感谢大家的阅读!

相关推荐
说私域3 小时前
基于定制开发开源AI智能名片S2B2C商城小程序的会员存量池构建策略研究
人工智能·小程序·开源·零售
黄同学real8 小时前
微信小程序 XSS 防护知识整理
微信小程序·小程序·xss
车轮滚滚__10 小时前
uniapp 小程序 安卓苹果 短视频解决方案
ios·小程序·uni-app·安卓·html5
小羊Linux客栈18 小时前
Python小程序:上班该做点摸鱼的事情
开发语言·python·小程序·游戏程序
Nueuis18 小时前
微信小程序分页和下拉刷新
服务器·前端·微信小程序
276695829220 小时前
得物 小程序 6宫格 分析
java·python·小程序·得物·得物小程序·得物六宫格·六宫格验证码
MYmayue21 小时前
微信小程序封装选择年月日时分秒组件
微信小程序·小程序
Nightne1 天前
总结小程序的坑
微信小程序
niech_cn1 天前
仿微信上传头像,实现拍摄、相册选择、手动缩放、裁剪、蒙版、撤回、还原、上传微信本地文件功能
微信·小程序