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

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

相关推荐
耀耀切克闹灬8 小时前
Skyline 渲染问题记录以及总结
微信小程序
小程序开发X9 小时前
2026 深圳 APP 开发甄选:技术架构搭建、全流程落地、综合选型解读
微信小程序·小程序·app开发
Kingexpand_com10 小时前
培训机构排课管理小程序设计与功能实现思路
小程序·软件开发·小程序定制开发·培训排课·培训机构·排课小程序
EatFan12 小时前
一个二维码背后的系统设计:批次生成、绑定、扫码与数据统计怎么做?
java·后端·微信小程序·二维码·qrcode
扶风ff14 小时前
练题簿企业培训方案:统一题库、在线任务与岗位考核
学习·小程序
AI行业应用研究14 小时前
会务问答机器人落地拆解:三级路由、知识库组织与防幻觉——会务小程序能自己回答参会者提问吗?
大数据·人工智能·安全·小程序·架构
盟道科技15 小时前
小程序订阅消息大规模投递实践:频控令牌池、Redis限流与失败补偿设计
分布式·算法·小程序
m0_5873830015 小时前
本地同城无人机作业接单系统源码:架构拆解与抢单调度实现
java·小程序·架构·需求分析
2501_9159090616 小时前
怎么用 FlutterFlow 把应用发布到 App Store?
android·ios·小程序·https·uni-app·iphone·webview
白远山1 天前
家政服务家政社区派单实战:调度系统架构设计与实现指南
java·开发语言·小程序·架构·需求分析