当前位置: 首页 > news >正文

uniCloud云开发----7、uniapp通过uni-swiper-dot实现轮播图

uniapp通过uni-swiper-dot实现轮播图

  • 前言
  • 效果图
    • 1、官网实现的效果
    • 2、需求中使用到的效果图
  • 官网提供的效果图源码
    • 1、html部分
    • 2、js部分
    • 3、css部分
  • 根据需求调整轮播图

前言

uni-swiper-dot.文档
uni-swiper-dot 轮播图指示点 - DCloud 插件市场
本次展示根据需求制作的和官网用到的轮播图和源码

效果图

1、官网实现的效果

在这里插入图片描述

2、需求中使用到的效果图

在这里插入图片描述

官网提供的效果图源码

使用官网的代码需要下载uni-section
uni-swiper-dot提供的api
在这里插入图片描述
可以通过改变uni-swiper-dot的参数来实现轮播图的样式和颜色以及距离等
在这里插入图片描述

1、html部分

<template><view class="content"><uni-swiper-dot class="uni-swiper-dot-box" @clickItem=clickItem :info="info" :current="current" :mode="mode":dots-styles="dotsStyles" field="content"><swiper class="swiper-box" @change="change" :current="swiperDotIndex"><swiper-item v-for="(item, index) in 3" :key="index"><view class="swiper-item" :class="'swiper-item' + index"><text style="color: #fff; font-size: 32px;">{{index+1}}</text></view></swiper-item></swiper></uni-swiper-dot><uni-section title="模式选择" type="line"><view class="example-body"><view :class="{ active: modeIndex === 0 }" class="example-body-item" @click="selectMode('default', 0)"><text class="example-body-item-text">default</text></view><view :class="{ active: modeIndex === 1 }" class="example-body-item" @click="selectMode('dot', 1)"><textclass="example-body-item-text">dot</text></view><view :class="{ active: modeIndex === 2 }" class="example-body-item" @click="selectMode('round', 2)"><text class="example-body-item-text">round</text></view><view :class="{ active: modeIndex === 3 }" class="example-body-item" @click="selectMode('nav', 3)"><textclass="example-body-item-text">nav</text></view><view :class="{ active: modeIndex === 4 }" class="example-body-item" @click="selectMode('indexes', 4)"><text class="example-body-item-text">indexes</text></view></view></uni-section><uni-section title="颜色样式选择" type="line"><view class="example-body"><template v-if="mode !== 'nav'"><view v-for="(item, index) in dotStyle" :class="{ active: styleIndex === index }" :key="index"class="example-body-item" @click="selectStyle(index)"><view :style="{ 'background-color': item.selectedBackgroundColor, border: item.selectedBorder }"class="example-body-dots" /><view :style="{ 'background-color': item.backgroundColor, border: item.border }"class="example-body-dots" /><view :style="{ 'background-color': item.backgroundColor, border: item.border }"class="example-body-dots" /></view></template><template v-if="mode === 'nav'"><view v-for="(item, index) in dotStyle" :class="{ active: styleIndex === index }" :key="index":style="{ 'background-color': item.selectedBackgroundColor }" class="example-body-item"@click="selectStyle(index)"><text class="example-body-item-text" :style="{ color: item.color }">内容</text></view></template></view></uni-section></view>
</template>

2、js部分

<script>export default {components: {},data() {return {info: [{colorClass: 'uni-bg-red',url: 'https://web-assets.dcloud.net.cn/unidoc/zh/shuijiao.jpg',content: '内容 A'},{colorClass: 'uni-bg-green',url: 'https://web-assets.dcloud.net.cn/unidoc/zh/shuijiao.jpg',content: '内容 B'},{colorClass: 'uni-bg-blue',url: 'https://web-assets.dcloud.net.cn/unidoc/zh/shuijiao.jpg',content: '内容 C'}],dotStyle: [{backgroundColor: 'rgba(0, 0, 0, .3)',border: '1px rgba(0, 0, 0, .3) solid',color: '#fff',selectedBackgroundColor: 'rgba(0, 0, 0, .9)',selectedBorder: '1px rgba(0, 0, 0, .9) solid'},{backgroundColor: 'rgba(255, 90, 95,0.3)',border: '1px rgba(255, 90, 95,0.3) solid',color: '#fff',selectedBackgroundColor: 'rgba(255, 90, 95,0.9)',selectedBorder: '1px rgba(255, 90, 95,0.9) solid'},{backgroundColor: 'rgba(83, 200, 249,0.3)',border: '1px rgba(83, 200, 249,0.3) solid',color: '#fff',selectedBackgroundColor: 'rgba(83, 200, 249,0.9)',selectedBorder: '1px rgba(83, 200, 249,0.9) solid'}],modeIndex: -1,styleIndex: -1,current: 0,mode: 'default',dotsStyles: {},swiperDotIndex: 0}},onLoad() {},methods: {change(e) {this.current = e.detail.current},selectStyle(index) {this.dotsStyles = this.dotStyle[index]this.styleIndex = index},selectMode(mode, index) {this.mode = modethis.modeIndex = indexthis.styleIndex = -1this.dotsStyles = this.dotStyle[0]},clickItem(e) {this.swiperDotIndex = e},onBanner(index) {console.log(22222, index);}}}
</script>

3、css部分

<style lang="scss">.swiper-box {height: 200px;}.swiper-item {/* #ifndef APP-NVUE */display: flex;/* #endif */flex-direction: column;justify-content: center;align-items: center;height: 200px;color: #fff;}.swiper-item0 {background-color: #cee1fd;}.swiper-item1 {background-color: #b2cef7;}.swiper-item2 {background-color: #cee1fd;}.image {width: 750rpx;}/* #ifndef APP-NVUE */::v-deep .image img {-webkit-user-drag: none;-khtml-user-drag: none;-moz-user-drag: none;-o-user-drag: none;user-drag: none;}/* #endif */@media screen and (min-width: 500px) {.uni-swiper-dot-box {width: 400px;margin: 0 auto;margin-top: 8px;}.image {width: 100%;}}.uni-bg-red {background-color: #ff5a5f;}.uni-bg-green {background-color: #09bb07;}.uni-bg-blue {background-color: #007aff;}.example-body {/* #ifndef APP-NVUE */display: flex;/* #endif */flex-direction: row;padding: 20rpx;}.example-body-item {flex-direction: row;justify-content: center;align-items: center;margin: 15rpx;padding: 15rpx;height: 60rpx;/* #ifndef APP-NVUE */display: flex;padding: 0 15rpx;/* #endif */flex: 1;border-color: #e5e5e5;border-style: solid;border-width: 1px;border-radius: 5px;}.example-body-item-text {font-size: 28rpx;color: #333;}.example-body-dots {width: 16rpx;height: 16rpx;border-radius: 50px;background-color: #333333;margin-left: 10rpx;}.active {border-style: solid;border-color: #007aff;border-width: 1px;}
</style>

根据需求调整轮播图

其中使用到了轮播头图
其中使用到了swiper的circular autoplay两个参数
circular:是否采用衔接滑动,即播放到末尾后重新回到开头
autoplay:是否自动切换
官网提供的swiper的api
官网提供的swiper的api

<template><view class='home'><view class='home_swiper'><uni-swiper-dot class="uni-swiper-dot-box" @clickItem=clickItem :info="info" :current="current" :mode="mode":dots-styles="dotsStyles" field="content"><swiper class="swiper-box" @change="change" :current="swiperDotIndex" circular autoplayeasing-function="easeInOutCubic"><swiper-item v-for="(item, index) in info" :key="index"><view class="swiper-item" :class="'swiper-item' + index" @click="SwItemClick(item.nextUrl)"><!-- <text style="color: #fff; font-size: 32px;">{{item.content}}</text> --><!-- <img :src="item.url" alt="" style='width:100%;height:100%'> --><div class='switemImage' :style="{backgroundImage: 'url('+item.url+')'}" /></view></swiper-item></swiper></uni-swiper-dot></view></view>
</template><script>const homeSwiper = uniCloud.importObject("homeSwiper")export default {components: {},data() {return {info: [{colorClass: 'uni-bg-red',url: 'https://web-assets.dcloud.net.cn/unidoc/zh/shuijiao.jpg',content: '内容 A',nextUrl: '/pages/place/place'},{colorClass: 'uni-bg-green',url: 'https://web-assets.dcloud.net.cn/unidoc/zh/shuijiao.jpg',content: '内容 B'},{colorClass: 'uni-bg-blue',url: 'https://web-assets.dcloud.net.cn/unidoc/zh/shuijiao.jpg',content: '内容 C'},{colorClass: 'uni-bg-blue',url: 'https://web-assets.dcloud.net.cn/unidoc/zh/shuijiao.jpg',content: '内容 C'},{colorClass: 'uni-bg-blue',url: 'https://web-assets.dcloud.net.cn/unidoc/zh/shuijiao.jpg',content: '内容 C'},{colorClass: 'uni-bg-blue',url: 'https://web-assets.dcloud.net.cn/unidoc/zh/shuijiao.jpg',content: '内容 C'},{colorClass: 'uni-bg-blue',url: 'https://web-assets.dcloud.net.cn/unidoc/zh/shuijiao.jpg',content: '内容 C'}],current: 0,mode: 'default',dotsStyles: {backgroundColor: 'rgba(0, 0, 0, .3)',border: '1px rgba(0, 0, 0, .3) solid',color: '#fff',selectedBackgroundColor: 'rgba(0, 0, 0, .9)',selectedBorder: '1px rgba(0, 0, 0, .9) solid'},swiperDotIndex: 0}},onLoad() {this.getData()},methods: {change(e) {this.current = e.detail.current},clickItem(e) {this.swiperDotIndex = e},SwItemClick(e) {console.log(e)uni.switchTab({url: e})},getData() {homeSwiper.get('111').then(res=>{console.log(res.data)})}},}
</script><style lang="scss" scoped>.home {position: absolute;height: 100%;width: 100%;background-color: rgb(241, 236, 229);.swiper-box {height: 20rem;}.swiper-item {/* #ifndef APP-NVUE */display: flex;/* #endif */flex-direction: column;justify-content: center;align-items: center;height: 20rem;color: #fff;}.swiper-item0 {background-color: #cee1fd;}.swiper-item1 {background-color: #b2cef7;}.swiper-item2 {background-color: #cee1fd;}.image {width: 750rpx;}::v-deep .uni-swiper__dots-box {justify-content: left;left: 2rem;.uni-swiper__dots-item {margin-left: 0px}}.switemImage {width: 100%;height: 100%;background-size: cover;background-repeat: no-repeat;background-position: center center}}
</style>

相关文章:

uniCloud云开发----7、uniapp通过uni-swiper-dot实现轮播图

uniapp通过uni-swiper-dot实现轮播图前言效果图1、官网实现的效果2、需求中使用到的效果图官网提供的效果图源码1、html部分2、js部分3、css部分根据需求调整轮播图前言 uni-swiper-dot.文档 uni-swiper-dot 轮播图指示点 - DCloud 插件市场 本次展示根据需求制作的和官网用到…...

IM即时通讯构建企业协同生态链

在当今互联网信息飞速发展的时代&#xff0c;随着企业对协同办公要求的提高&#xff0c;协同办公的定义提升到了智能化办公的范畴。大多企业都非常重视构建连接用户、员工和合作伙伴的生态平台&#xff0c;利用即时通讯软件解决企业内部的工作沟通、信息传递和知识共享等问题。…...

Python实现构建gan模型, 输入一个矩阵和两个参数值,输出一个矩阵

构建一个GAN模型,使用Python实现,该模型将接受一个矩阵和两个参数值作为输入,并输出另一个矩阵。GAN(生成对抗网络)是一种深度学习模型,由生成器和判别器两部分组成,可以用于生成具有一定规律性的数据,如图像或音频。 # 定义生成器 def make_generator(noise_dim, dat…...

开学准备哪些电容笔?ipad触控笔推荐平价

在现代&#xff0c;数码产品的发展受到高技术的驱动。不管是在工作上&#xff0c;还是在学习上&#xff0c;大的显示屏可以使图像更加清晰。Ipad将成为我们日常生活中不可或缺的一部分&#xff0c;无论现在或将来。如果ipad配上一款方便操作的电容笔&#xff0c;将极大地提高我…...

放下和拿起 解放自己

放下太难&#xff0c;从过去中解放自己 工作这么久了&#xff0c;第一次不拿包上班&#xff0c;真爽 人的成长都是在碰撞和摸索中产生的&#xff0c;通过摸索&#xff0c;知道自己能力的边界和欲望的边界以及身体的边界&#xff0c;这三个决定了 你能做什么 你能享受什么&…...

100%BIM学员的疑惑:不会CAD可以学Revit吗?

在新一轮科技创新和产业变革中&#xff0c;信息化与建筑业的融合发展已成为建筑业发展的方向&#xff0c;将对建筑业发展带来战略性和全局性的影响。 建筑业是传统产业&#xff0c;推动建筑业科技创新&#xff0c;加快推进信息化发展&#xff0c;激发创新活力&#xff0c;培育…...

经常会采坑的javascript原型应试题

一&#xff0e; 前言 原型和原型链在面试中历来备受重视&#xff0c;经常被提及。说难可能也不太难&#xff0c;但要真正完全理解&#xff0c;吃透它&#xff0c;还是要多下功夫的。 下面为大家简单阐述我对原型和原型链的理解&#xff0c;若是觉得有说的不对的地方&#xff…...

完全背包—动态规划

一、背包问题概述 如图&#xff0c;完全背包与01背包的区别只有一点&#xff1a;01背包中每个物品只能取一个而完全背包中每个物品可以取无数个。解决完全背包问题必须首先弄明白01背包&#xff0c;不清楚的可以看我的这篇文章01背包—动态规划。 二、例题 重量价值物品0115物…...

消息队列MQ介绍

消息队列技术是分布式应用间交换信息的一种技术。消息队列可驻留在内存或磁盘上,队列存储消息直到它们被应用程序读走。通过消息队列&#xff0c;应用程序可独立地执行--它们不需要知道彼此的位置、或在继续执行前不需要等待接收程序接收此消息。 消息中间件概述 消息队列技术是…...

C语言进阶(八)—— 链表

1. 链表基本概念1.1 什么是链表链表是一种常用的数据结构&#xff0c;它通过指针将一些列数据结点&#xff0c;连接成一个数据链。相对于数组&#xff0c;链表具有更好的动态性&#xff08;非顺序存储&#xff09;。数据域用来存储数据&#xff0c;指针域用于建立与下一个结点的…...

手工测试用例就是自动化测试脚本——使用ruby 1.9新特性进行自动化脚本的编写

昨天因为要装watir-webdriver的原因将用了快一年的ruby1.8.6升级到了1.9。由于1.9是原生支持unicode编码&#xff0c;所以我们可以使用中文进行自动化脚本的编写工作。 做了简单的封装后&#xff0c;我们可以实现如下的自动化测试代码。请注意&#xff0c;这些代码是可以正确运…...

RockerMQ简介和单节点部署

目录一、RockerMQ简介二、Linux中单节点部署1、准备工作2、下载和解压3、修改初始内存4、启动5、查看进程6、发送接收消息测试7、关闭三、控制台的安装与启动(可视化页面)1、修改配置&#xff08;1&#xff09;修改端口号&#xff08;2&#xff09;指定RocketMQ的name server地…...

SFP光纤笼子 别称 作用 性能要点 工程要素

Hqst盈盛电子导读&#xff1a;2023年&#xff0c;Hqst盈盛电子于下属五金部开发生产SFP光纤连接器笼子等系列产品&#xff0c;所有产品生产及性标准都将参照连接器产品常用测试标准EIA-364-C等标准&#xff0c;以下为我司常规SFP光纤连接器基本性能要求SFP光纤笼子别称&#xf…...

[HarekazeCTF2019]Easy Notes

知识点&#xff1a;session 反序列化&#xff0c;代码审计代码分析 flag.php 中有个 is_admin 函数的判断。 在 lib.php 中有 is_admin 函数&#xff0c;需要 session[admin] 为 true&#xff0c;或者通过文件读取的方式。 在 index.php 中的 include 并不能使用伪协议读取 …...

Java学习-IO流-字符流-FileReader

Java学习-IO流-字符流-FileReader 字符流 字节流 字符集 输入流&#xff1a;默认一次读一个字节&#xff0c;遇到中文时一次读多个字节 输出流&#xff1a;底层把数据按照指定编码方式编码&#xff0c;变成字节写入文件 使用场景&#xff1a;纯文本文件读写 // …...

python攻陷米哈游《元神》数据?详情请看文章。。

前言 嗨喽&#xff0c;大家好呀~这里是爱看美女的茜茜呐 《原神》是由米哈游自研的一款全新开放世界冒险RPG。 里面拥有许多丰富得角色&#xff0c;让玩家为之着迷~ 今天&#xff0c;我们就来用python探索一下原神游戏角色信息&#xff01; 标题大家看看就好了哈~&#xff08…...

【unity细节】基于unity子对象(如相机)为什么无法进行z轴的拖拽移动和z轴自动归位的问题

&#x1f468;‍&#x1f4bb;个人主页&#xff1a;元宇宙-秩沅 hallo 欢迎 点赞&#x1f44d; 收藏⭐ 留言&#x1f4dd; 加关注✅! 本文由 秩沅 原创 收录于专栏&#xff1a;unity细节和bug ⭐基于unity子对象为什么无法进行z轴的拖拽移动和z轴自动归位⭐ 文章目录⭐基于u…...

如何维护固态继电器?

固态继电器是SSR的简称&#xff0c;是由微电子电路、分立电子器件和电力电子功率器件组成的非接触式开关。隔离装置用于实现控制端子与负载终端之间的隔离。固态继电器的输入端使用微小的控制信号直接驱动大电流负载。那么&#xff0c;如何保养固态继电器呢&#xff1f; 在为小…...

Sprng依赖注入(三):构造方法注入是如何工作的?

前言这是Spring依赖注入系列的第三篇&#xff0c;前两篇主要分析了Spring bean依赖属性注入的两种方式&#xff0c;是字段注入和setter方法注入&#xff0c;单独比较这两种方式&#xff0c;会发现其过程和工作原理非常类似&#xff0c;那么构造方法注入会不会也和前两种比较类似…...

「1」指针进阶——详解

&#x1f680;&#x1f680;&#x1f680;大家觉不错的话&#xff0c;就恳求大家点点关注&#xff0c;点点小爱心&#xff0c;指点指点&#x1f680;&#x1f680;&#x1f680; 目录 &#x1f430;指针的回顾 &#x1f430;字符指针 &#x1f430;指针数组 &#x1f338;模…...

C++实现分布式网络通信框架RPC(3)--rpc调用端

目录 一、前言 二、UserServiceRpc_Stub 三、 CallMethod方法的重写 头文件 实现 四、rpc调用端的调用 实现 五、 google::protobuf::RpcController *controller 头文件 实现 六、总结 一、前言 在前边的文章中&#xff0c;我们已经大致实现了rpc服务端的各项功能代…...

三维GIS开发cesium智慧地铁教程(5)Cesium相机控制

一、环境搭建 <script src"../cesium1.99/Build/Cesium/Cesium.js"></script> <link rel"stylesheet" href"../cesium1.99/Build/Cesium/Widgets/widgets.css"> 关键配置点&#xff1a; 路径验证&#xff1a;确保相对路径.…...

第25节 Node.js 断言测试

Node.js的assert模块主要用于编写程序的单元测试时使用&#xff0c;通过断言可以提早发现和排查出错误。 稳定性: 5 - 锁定 这个模块可用于应用的单元测试&#xff0c;通过 require(assert) 可以使用这个模块。 assert.fail(actual, expected, message, operator) 使用参数…...

鸿蒙中用HarmonyOS SDK应用服务 HarmonyOS5开发一个生活电费的缴纳和查询小程序

一、项目初始化与配置 1. 创建项目 ohpm init harmony/utility-payment-app 2. 配置权限 // module.json5 {"requestPermissions": [{"name": "ohos.permission.INTERNET"},{"name": "ohos.permission.GET_NETWORK_INFO"…...

Ascend NPU上适配Step-Audio模型

1 概述 1.1 简述 Step-Audio 是业界首个集语音理解与生成控制一体化的产品级开源实时语音对话系统&#xff0c;支持多语言对话&#xff08;如 中文&#xff0c;英文&#xff0c;日语&#xff09;&#xff0c;语音情感&#xff08;如 开心&#xff0c;悲伤&#xff09;&#x…...

HTML前端开发:JavaScript 常用事件详解

作为前端开发的核心&#xff0c;JavaScript 事件是用户与网页交互的基础。以下是常见事件的详细说明和用法示例&#xff1a; 1. onclick - 点击事件 当元素被单击时触发&#xff08;左键点击&#xff09; button.onclick function() {alert("按钮被点击了&#xff01;&…...

【JavaSE】绘图与事件入门学习笔记

-Java绘图坐标体系 坐标体系-介绍 坐标原点位于左上角&#xff0c;以像素为单位。 在Java坐标系中,第一个是x坐标,表示当前位置为水平方向&#xff0c;距离坐标原点x个像素;第二个是y坐标&#xff0c;表示当前位置为垂直方向&#xff0c;距离坐标原点y个像素。 坐标体系-像素 …...

【C++从零实现Json-Rpc框架】第六弹 —— 服务端模块划分

一、项目背景回顾 前五弹完成了Json-Rpc协议解析、请求处理、客户端调用等基础模块搭建。 本弹重点聚焦于服务端的模块划分与架构设计&#xff0c;提升代码结构的可维护性与扩展性。 二、服务端模块设计目标 高内聚低耦合&#xff1a;各模块职责清晰&#xff0c;便于独立开发…...

Xen Server服务器释放磁盘空间

disk.sh #!/bin/bashcd /run/sr-mount/e54f0646-ae11-0457-b64f-eba4673b824c # 全部虚拟机物理磁盘文件存储 a$(ls -l | awk {print $NF} | cut -d. -f1) # 使用中的虚拟机物理磁盘文件 b$(xe vm-disk-list --multiple | grep uuid | awk {print $NF})printf "%s\n"…...

技术栈RabbitMq的介绍和使用

目录 1. 什么是消息队列&#xff1f;2. 消息队列的优点3. RabbitMQ 消息队列概述4. RabbitMQ 安装5. Exchange 四种类型5.1 direct 精准匹配5.2 fanout 广播5.3 topic 正则匹配 6. RabbitMQ 队列模式6.1 简单队列模式6.2 工作队列模式6.3 发布/订阅模式6.4 路由模式6.5 主题模式…...