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

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

基本使用,上代码:

<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>
样式

.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    是否采用衔接滑动
<!-- 属性 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. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-18 08:24:01       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-18 08:24:01       100 阅读
  3. 在Django里面运行非项目文件

    2024-06-18 08:24:01       82 阅读
  4. Python语言-面向对象

    2024-06-18 08:24:01       91 阅读

热门阅读

  1. ubuntu20.0.4安装pyqt5

    2024-06-18 08:24:01       28 阅读
  2. Neo4j图形数据库查询,Cypher语言详解

    2024-06-18 08:24:01       29 阅读
  3. opencv c++ 学习1

    2024-06-18 08:24:01       27 阅读
  4. c# 去掉字符串首尾的 特殊符号

    2024-06-18 08:24:01       33 阅读
  5. 【AI原理解析】— 字节豆包模型

    2024-06-18 08:24:01       44 阅读
  6. 24.自定义python日志handler

    2024-06-18 08:24:01       35 阅读
  7. MongoDB 索引限制

    2024-06-18 08:24:01       32 阅读
  8. 如何优化 Bash 脚本的执行效率?

    2024-06-18 08:24:01       31 阅读
  9. 060、Python 模块:管理函数

    2024-06-18 08:24:01       33 阅读
  10. git配置1-不同的项目使用不同用户名或邮箱

    2024-06-18 08:24:01       32 阅读
  11. 使用 TypeScript 写一个自己的 NPM 库

    2024-06-18 08:24:01       40 阅读
  12. 如果搜索一定超时,如何用dp来以空间换时间

    2024-06-18 08:24:01       29 阅读
  13. 云计算 | (三)云使能技术

    2024-06-18 08:24:01       30 阅读