初识微信小程序之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. 程序swiperswiper-item基本使用

    2024-03-16 08:34:02       8 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-03-16 08:34:02       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-16 08:34:02       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-16 08:34:02       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-16 08:34:02       20 阅读

热门阅读

  1. Node.js 中的 HTTP 模块教程

    2024-03-16 08:34:02       20 阅读
  2. 个人商城系统开源(注册)

    2024-03-16 08:34:02       19 阅读
  3. 嵌入式学习day38 HTML

    2024-03-16 08:34:02       18 阅读
  4. 【Android】源码中的工厂方法模式

    2024-03-16 08:34:02       19 阅读
  5. Kafka主题二三事

    2024-03-16 08:34:02       21 阅读
  6. 【 React 】在React 项目是如何捕获错误的?

    2024-03-16 08:34:02       22 阅读
  7. 考研模拟面试-题目【攻略】

    2024-03-16 08:34:02       22 阅读