当前位置:网站首页>【微信小程序】好看的轮播图组件
【微信小程序】好看的轮播图组件
2022-07-04 03:52:00 【Pulseum】
微信小程序好看的轮播图组件效果示例
使用步骤
第一步:
新建components文件夹
第二步:
按照以下目录创建文件:(文件名可以自定义,但后面引入组件时应保持前后一致)
第三步:
各个文件的代码:
customSwiper.js:
// components/customSwiper.js
Component({
/** * 组件的属性列表 */
properties: {
imgUrls: Array,
},
/** * 组件的初始数据 */
data: {
currentIndex: 0
},
/** * 组件的方法列表 */
methods: {
swiperChange(e) {
this.setData({
currentIndex: e.detail.current
});
}
}
})
customSwiper.json:
{
"component": true,
"usingComponents": {
}
}
customSwiper.wxml:
<!--components/customSwiper.wxml-->
<swiper indicator-dots="false" autoplay="{
{true}}" interval="5000" indicator-dots="{
{false}}" indicator-color='#8a8a8a' indicator-active-color='#333' circular="true" class="swiper-block" bindchange="swiperChange" previous-margin="100rpx" next-margin="100rpx" current="{
{0}}">
<block wx:for="{
{imgUrls}}" wx:index="{
{index}}" wx:key="index">
<swiper-item class="swiper-item ">
<image mode="aspectFill" src="{
{item}}" class="slide-image {
{currentIndex == index ? 'active' : 'common'}}" />
</swiper-item>
</block>
</swiper>
customSwiper.wxss:
/* components/customSwiper.wxss */
page{
background-color: #fff;
}
.swiper-block {
background: #fff;
height: 500rpx;
width: 100%;
}
.swiper-item{
display: flex;
flex-direction: column;
justify-content: start;
align-items: flex-start;
overflow: unset;
width: 550rpx;
height: 450rpx;
padding-top: 70rpx;
padding-bottom: 20rpx;
box-sizing: border-box;
}
.slide-image{
height: 300rpx;
width: 450rpx;
border-radius: 10rpx;
margin: 0rpx 50rpx ;
z-index: 1;
box-shadow: 10rpx 5px 40rpx rgba(0, 0, 0,0.5);
}
.active{
transform: scale(1.3);
transition: all .5s ease-in 0s;
z-index: 20;
opacity: 1;
}
.common{
transform: scale(1);
transition: all .5s ease-in 0s;
z-index: 0;
opacity: 0.4;
}
.dots-box{
display: flex;
justify-content: center;
align-items: center;
}
.dots{
width: 30rpx;
height: 6rpx;
margin: 0 4rpx;
background-color: #aaa;
margin-top: -80rpx;
}
.bg-333{
background-color: #333;
}
第四步:
在所需页面引入该组件
以在home页面引入为例
home.wxml:
<!--pages/home/home.wxml-->
<view>
<!-- 轮播图2 -->
<custom-swiper imgUrls="{
{carouselImgUrls}}" />
</view>
home.js: (轮播图数据根据自己的图片路径更改)
// pages/home/home.js
Page({
/** * 页面的初始数据 */
data: {
// 轮播图2数据 (轮播图数据根据自己的图片路径更改)
carouselImgUrls:[
"/images/yyqx1.jpg",
"/images/yyqx2.jpg",
"/images/yyqx3.jpg",
"/images/yyqx4.jpg",
"/images/yyqx5.jpg"
],
},
/** * 生命周期函数--监听页面加载 */
onLoad: function (options) {
},
/** * 生命周期函数--监听页面初次渲染完成 */
onReady: function () {
},
/** * 生命周期函数--监听页面显示 */
onShow: function () {
},
/** * 生命周期函数--监听页面隐藏 */
onHide: function () {
},
/** * 生命周期函数--监听页面卸载 */
onUnload: function () {
},
/** * 页面相关事件处理函数--监听用户下拉动作 */
onPullDownRefresh: function () {
},
/** * 页面上拉触底事件的处理函数 */
onReachBottom: function () {
},
/** * 用户点击右上角分享 */
onShareAppMessage: function () {
}
})
home.json:
{
"usingComponents": {
"custom-swiper": "../../components/customSwiper/customSwiper"
}
}
home.wxss: 无需增加样式(组件带有)
结束
根据以上步骤就可以正确显示轮播图组件了,只需更改图片路径即可。
边栏推荐
- (指针)自己写一个比较字符串大小的函数,功能与strcmp类似。
- ROS2中CMake编译选项的设置
- 【微服务|openfeign】feign的两种降级方式|Fallback|FallbackFactory
- tdk-lambda电源主要应用
- Parameterization of controls in katalon
- The difference between bagging and boosting in machine learning
- Unity 绘制弹球和台球的运动轨迹
- Redis cluster uses Lua script. Lua script can also be used for different slots
- 仿《游戏鸟》源码 手游发号评测开服开测合集专区游戏下载网站模板
- 苹果CMS仿西瓜视频大气响应式视频模板源码
猜你喜欢
Leetcode skimming: binary tree 07 (maximum depth of binary tree)
dried food! Generation of rare samples based on GaN
Global exposure and roller shutter exposure of industrial cameras
Exercises in quantum mechanics
leetcode刷题:二叉树04(二叉树的层序遍历)
资深开发人员告诉你,怎样编写出优秀的代码?
【CSRF-01】跨站请求伪造漏洞基础原理及攻防
Lnk2038 detected a mismatch of "runtimelibrary": the value "md_dynamicrelease" does not match the value "mdd_dynamicdebug" (in main.obj)
leetcode刷题:二叉树09(二叉树的最小深度)
微信公众号无限回调授权系统源码
随机推荐
leetcode刷题:二叉树08(N叉树的最大深度)
vim正确加区间注释
微信脑力比拼答题小程序_支持流量主带最新题库文件
Idea modify body color
VIM mapping command
The maximum expiration time of client secret in azure ad application registration is modified to 2 years
架构训练毕业设计+总结
tdk-lambda电源主要应用
Distributed system: what, why, how
Graduation project: design seckill e-commerce system
普源DS1000Z系列数字示波器在通信原理实验中的应用方案
Perf simple process for multithreaded profile
ctf-pikachu-XSS
JS realizes the effect of text scrolling marquee
vim映射命令
(指针)自己写一个比较字符串大小的函数,功能与strcmp类似。
统计遗传学:第三章,群体遗传
How was my life in 2021
Cesiumjs 2022^ source code interpretation [0] - article directory and source code engineering structure
PPt 教程,如何在 PowerPoint 中将演示文稿另存为 PDF 文件?