【微信小程序】swiper和swiper-item组件的基本使用

✅作者简介:CSDN内容合伙人、阿里云专家博主、51CTO专家博主🏆
📃个人主页:hacker707的csdn博客
🔥系列专栏:微信小程序
💬个人格言:不断的翻越一座又一座的高山,那样的人生才是我想要的。这一马平川,一眼见底的活,我不想要,我的人生,我自己书写,余生很长,请多关照,我的人生,敬请期待💖💖💖

在这里插入图片描述

实现轮播图效果

在这里插入图片描述

list.wxml

<!--轮播图的结构-->
<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>

list.wxss

/* 轮播图样式 */
.swiper-container{
    height: 150px;
}

.item{
    height: 100%;
    line-height: 150px;
    text-align: center;
}

swiper-item:nth-child(1) .item{
    background-color: lightgreen;
}
swiper-item:nth-child(2) .item{
    background-color: lightskyblue;
}
swiper-item:nth-child(3) .item{
    background-color: lightpink;
}

swiper组件的常用属性

属性类型默认值说明
indicator-dotsbooleanfalse是否显示面板提示点
indictor-colorcolorrgba(0,0,0,3)指示点颜色
indictor-active-colorcolor#000000当前选择的指示点颜色
autoplaybooleanfalse是否自动切换
intervalnumber5000自动切换时间间隔
circularbooleanfalse是否采用衔接滑动

✅显示指示点颜色

在这里插入图片描述

✅设置指示点颜色

在这里插入图片描述
✅设置当前选择的指示点颜色

在这里插入图片描述
✅设置1秒自动切换

在这里插入图片描述

✅设置衔接滑动

在这里插入图片描述

结束语

以上就是微信小程序之swiper和swiper-item组件的基本使用
持续更新微信小程序教程,欢迎大家订阅系列专栏🔥微信小程序
你们的支持就是hacker创作的动力💖💖💖

在这里插入图片描述

  • 82
    点赞
  • 119
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 28
    评论
是的,可以使用swiper和scroll-view组件来实现微信小程序的左右分页功能。 首先,在wxml文件中添加swiper和scroll-view组件,并设置相应的属性。 ```html <swiper class="swiper-container" current="{{current}}" duration="{{500}}" style="height:{{pageHeight}}px"> <swiper-item> <scroll-view class="scroll-view" scroll-x="{{true}}" scroll-y="{{false}}" style="width:{{windowWidth}}px;height:{{pageHeight}}px;"> <!--第一页内容--> </scroll-view> </swiper-item> <swiper-item> <scroll-view class="scroll-view" scroll-x="{{true}}" scroll-y="{{false}}" style="width:{{windowWidth}}px;height:{{pageHeight}}px;"> <!--第二页内容--> </scroll-view> </swiper-item> <!--更多swiper-item--> </swiper> ``` 其中,swiper组件设置了current属性,用于控制当前显示的页码;scroll-view组件设置了scroll-x属性,用于开启水平方向的滚动,并设置了样式宽度为屏幕宽度,高度为页面高度。 接着,在js文件中,监听swiper组件的change事件,用于动态更新当前页码。 ```javascript Page({ data: { current: 0, windowWidth: wx.getSystemInfoSync().windowWidth, pageHeight: wx.getSystemInfoSync().windowHeight }, onLoad: function () { //... }, onPageChange: function (e) { this.setData({ current: e.detail.current }) } }) ``` 最后,在样式文件中,设置swiper-container和scroll-view的样式,用于实现左右分页效果。 ```css .swiper-container { overflow: hidden; position: relative; } .scroll-view { white-space: nowrap; } .swiper-item { display: inline-block; vertical-align: top; width: 100%; } ``` 以上就是使用swiper和scroll-view组件实现微信小程序左右分页功能的方法。
评论 28
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hacker707

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值