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

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

相关推荐
低代码布道师1 小时前
医疗小程序10预约挂号日历切换
低代码·小程序
一 乐3 小时前
健康打卡|健康管理|基于java+vue+的学生健康打卡系统设计与实现(源码+数据库+文档)
android·java·数据库·vue.js·spring boot·微信小程序
翼龙云_cloud9 小时前
阿里云渠道商:如何在阿里云 ECS 上搭建微信小程序服务?
运维·服务器·阿里云·微信小程序·小程序·云计算
墨着染霜华9 小时前
UniApp 微信小程序分享
微信小程序·uni-app
2501_9159214311 小时前
Windows 系统下的 IPA 加密工具实战指南,如何在非 macOS 环境完成 IPA 混淆、加固与工程化处理
android·windows·macos·ios·小程序·uni-app·iphone
小小王app小程序开发13 小时前
从 0 到 1 搭建盈利闭环:废品回收小程序的场景分层与增值服务设计
小程序
狂团商城小师妹13 小时前
JAVA同城服务场馆预约门店预约健身房瑜伽馆预约系统支持H5小程序APP源码
java·开发语言·小程序
Javashop_jjj13 小时前
三勾软件|基础SpringBoot餐饮点餐系统,小程序+公众号+APP
spring boot·后端·小程序
性野喜悲14 小时前
ts+unispp小程序textarea多行文本高度自使用
java·前端·小程序
wx_ywyy679815 小时前
商城小程序直播带货功能开发:直播间搭建、商品挂载与互动功能实现方案
小程序·小程序开发·商城小程序·小程序制作·小程序商城·商城小程序开发·商城小程序制作