初识微信小程序之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>

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

相关推荐
CHU7290352 小时前
废品回收小程序前端功能设计逻辑与实践
前端·小程序
小小王app小程序开发2 小时前
上门家政服务小程序盈利模式分析(附技术落地要点)
小程序
码云数智-大飞2 小时前
微信商城小程序怎么弄?2026年主流小程序商城平台对比
微信小程序
蜕变菜鸟2 小时前
小程序分享
小程序
2501_915106322 小时前
iOS 如何绕过 ATS 发送请求,iOS调试
android·ios·小程序·https·uni-app·iphone·webview
计算机毕设指导63 小时前
基于微信小程序的非物质文化遗产推广管理系统【源码文末联系】
java·spring boot·mysql·微信小程序·小程序·tomcat·maven
说私域3 小时前
基于开源AI智能名片S2B2C商城小程序视角下的消费需求激发与企业机遇挖掘
人工智能·小程序·开源·流量运营·私域运营
我想吃辣条3 小时前
从 0 到 1 开发一款记账小程序的设计与实现
小程序·记账
软件聚导航12 小时前
马年、我用AI写了个“打工了马” 小程序
人工智能·ui·微信小程序
2501_9159184118 小时前
常见 iOS 抓包工具的使用,从代理抓包、设备抓包到数据流抓包
android·ios·小程序·https·uni-app·iphone·webview