原生轮播图(下一页切换,附带指示器)

下面是目录结构:

index.html

<!DOCTYPE html>
<html lang="zh"><head><meta charset="UTF-8" /><meta http-equiv="X-UA-Compatible" content="IE=edge" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>无缝轮播图</title><link rel="stylesheet" href="./css/index.css" /><link rel="stylesheet" href="./css/iconfont.css"/></head><body><div class="carousel-container"><div class="carousel-list"><div class="carousel-item item-1">1</div><div class="carousel-item item-2">2</div><div class="carousel-item item-3">3</div></div><div class="carousel-arrow carousel-arrow-left"><i class="iconfont icon-left"></i></div><div class="carousel-arrow carousel-arrow-right"><i class="iconfont icon-right"></i></div><div class="indicator"><span class="active"></span><span></span><span></span></div></div><script src="./js/index.js"></script></body>
</html>

 index.js

const doms = {carouselList: document.querySelector('.carousel-list'),arrowLeft: document.querySelector('.carousel-arrow-left'),arrowRight: document.querySelector('.carousel-arrow-right'),indicators: document.querySelectorAll('.indicator span'),
};
const count = doms.indicators.length; // 轮播图的数量
let curIndex = 0; // 当前轮播图的索引
function moveTo(index) {doms.carouselList.style.transform = `translateX(-${index}00%)`;doms.carouselList.style.transition = '.5s';// 去掉指示器的选中效果var active = document.querySelector('.indicator span.active');active.classList.remove('active');// 添加选中的指示器doms.indicators[index].classList.add('active');curIndex = index;
}doms.indicators.forEach((item, i) => {item.onclick = function () {moveTo(i);};
});function init() {const firstCloned = doms.carouselList.firstElementChild.cloneNode(true);const lastCloned = doms.carouselList.lastElementChild.cloneNode(true);lastCloned.style.marginLeft = '-100%';doms.carouselList.appendChild(firstCloned);doms.carouselList.insertBefore(lastCloned,doms.carouselList.firstElementChild);
}init();function moveLeft() {if (curIndex === 0) {doms.carouselList.style.transform = `translateX(-${count}00%)`;doms.carouselList.style.transition = 'none';//去掉过渡// 强制渲染 / 等待浏览器渲染后再执行,当读取浏览器dom的几何信息会强制回流doms.carouselList.clientHeight;moveTo(count - 1);} else {moveTo(curIndex - 1);}
}function moveRight() {if (curIndex === count - 1) {doms.carouselList.style.transform = `translateX(100%)`;doms.carouselList.style.transition = 'none';// 强制渲染 / 等待浏览器渲染后再执行doms.carouselList.clientHeight;moveTo(0);} else {moveTo(curIndex + 1);}
}doms.arrowLeft.onclick = moveLeft;
doms.arrowRight.onclick = moveRight;

iconfont.css

@font-face {font-family: "iconfont"; /* Project id  */src: url('iconfont.ttf?t=1714962297970') format('truetype');
}.iconfont {font-family: "iconfont" !important;font-size: 16px;font-style: normal;-webkit-font-smoothing: antialiased;-moz-osx-font-smoothing: grayscale;
}.icon-right:before {content: "\e662";
}.icon-left:before {content: "\e663";
}

index.css

* {margin: 0;padding: 0;box-sizing: border-box;
}.carousel-container {width: 500px;height: 300px;margin: 20px auto;position: relative;/* overflow: hidden; */outline: 10px solid #000;
}
.carousel-list {width: 100%;height: 100%;display: flex;position: relative;z-index: -1;
}
.carousel-item {height: 100%;flex: 0 0 100%;width: 100%;z-index: -1;display: flex;justify-content: center;align-items: center;font-size: 5em;
}
.carousel-item.item-1 {background: #fb5e56;
}
.carousel-item.item-2 {background: #febc2e;
}
.carousel-item.item-3 {background: #28c840;
}
.carousel-item img {display: block;width: 100%;height: 100%;object-fit: cover;
}.carousel-arrow {position: absolute;width: 50px;height: 50px;background: #000;border-radius: 50%;color: #fff;text-align: center;line-height: 50px;top: 50%;transform: translateY(-50%);opacity: 0.1;user-select: none;cursor: pointer;transition: 0.5s;
}
.carousel-arrow:hover {opacity: 0.7;
}
.carousel-arrow .iconfont {font-size: 1.5em;
}
.carousel-arrow-right {right: 10px;
}
.carousel-arrow-left {left: 10px;
}.indicator {position: absolute;display: flex;bottom: 10px;left: 50%;transform: translateX(-50%);
}.indicator span {width: 20px;height: 20px;border-radius: 50%;border: 2px solid #ccc;margin: 0 3px;cursor: pointer;
}
.indicator span.active {border-color: #fff;background: #fff;
}

iconfont.ttf 其实就是iconfont的字体文件,里面就是轮播图上一张和下一张的按钮,这边自行设置,文件就不放这里了

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/670050.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

STM32单片机实战开发笔记-独立看门狗IWDG

嵌入式单片机开发实战例程合集&#xff1a; 链接&#xff1a;https://pan.baidu.com/s/11av8rV45dtHO0EHf8e_Q0Q?pwd28ab 提取码&#xff1a;28ab IWDG模块测试 1、功能描述 STM32F10X内置两个看门狗&#xff0c;提供了更高的安全性&#xff0c;时间的精确下性和使用的灵活性…

58行代码把Llama 3扩展到100万上下文,任何微调版都适用 | 最新快讯

量子位公众号 QbitAI 堂堂开源之王 Llama 3&#xff0c;原版上下文窗口居然只有……8k&#xff0c;让到嘴边的一句“真香”又咽回去了。 在 32k 起步&#xff0c;100k 寻常的今天&#xff0c;这是故意要给开源社区留做贡献的空间吗&#xff1f; 开源社区当然不会放过这个机会&a…

性能工具使用

systemTap 采集工具 bcc 分析工具 sysstat 监控工具 netstat 网络监控工具 分类 tools/argdist: Display function parameter values as a histogram or frequency count. Examples.tools/bashreadline: Print entered bash commands system wide. Examples.tools/bpfli…

Socket学习记录

本次学习Socket的编程开发&#xff0c;该技术在一些通讯软件&#xff0c;比如说微信&#xff0c;QQ等有广泛应用。 网络结构 这些都是计算机网络中的内容&#xff0c;我们在这里简单回顾一下&#xff1a; UDP(User Datagram Protocol):用户数据报协议;TCP(Transmission Contr…

FastDFS - 无法获取服务端连接资源:can‘t create connection to/xx.xx.xx.xx:0

问题描述 根据官方文档 安装完FastDFS服务器后&#xff0c; 服务正常启动&#xff0c;但是在 SpringBoot 项目使用 fastdfs-client 客户端报错无法获取服务端连接资源&#xff1a;cant create connection to/xx.xx.xx.xx:0, 一系列排查发现是获取到的 tracker 端口为 0 。 co…

开源模型应用落地-CodeQwen模型小试-SQL专家测试(二)

一、前言 代码专家模型是基于人工智能的先进技术&#xff0c;它能够自动分析和理解大量的代码库&#xff0c;并从中学习常见的编码模式和最佳实践。这种模型可以提供准确而高效的代码建议&#xff0c;帮助开发人员在编写代码时避免常见的错误和陷阱。 通过学习代码专家模型&…

Linux:进程信号(一)信号的产生

目录 一、信号是什么&#xff1f; 二、Linux信号 三、信号处理方式 四、信号的产生 1、 通过终端按键产生信号 2、调用系统函数向进程发信号 3、 硬件异常产生信号 一、信号是什么&#xff1f; 在生活中&#xff0c;有许多信号&#xff0c;比如红绿灯&#xff0c;下课铃声…

一键 input 苹果 OpenELM,零门槛 Llama 3 教程,40+ 优质模型/数据集/教程,建议收藏!...

现在 AI 行业什么最火&#xff1f; 「大模型」一定仍然排在前三甲的位置。 自从 2022 年底 ChatGPT 面世以来&#xff0c;大模型在各行各业已经带来了太多的惊喜&#xff0c;应用场景愈发丰富&#xff0c;同时也带动了相关底层技术的普及与普适化。尤其是在开源模型繁荣发展之下…

CkickHouse JDBC 使用整理

1. pom 引入 <dependency><groupId>com.clickhouse</groupId><artifactId>clickhouse-jdbc</artifactId><version>0.4.6</version></dependency><dependency><groupId>org.roaringbitmap</groupId><arti…

星戈瑞CY7-COOH荧光探针,助力生物医学研究

CY7-COOH是一种近红外荧光染料&#xff0c;具有优异的光稳定性、高量子产率和强烈的荧光信号。此外&#xff0c;CY7-COOH还具有较长的激发和发射波长&#xff0c;使其在生物医学成像中具有较高的穿透力和较低的背景干扰。这使得CY7-COOH荧光探针在生物医学研究中具有诸多应用前…

YOLOv5网络结构解析

YOLOv5的实现细节解析&#xff1a;基础组件与实现细节 YOLO&#xff08;You Only Look Once&#xff09;系列作为目标检测领域的重要算法&#xff0c;以其速度快、性能好而著称。YOLOv5是该系列的最新版本&#xff0c;它在保持YOLO一贯的简洁高效特点的同时&#xff0c;进一步…

武汉星起航:跨境电商领域国际竞争力卓越,引领行业再上新台阶

在全球化浪潮的推动下&#xff0c;跨境电商行业日益成为各国经济交流与合作的重要桥梁。武汉星起航电子商务有限公司&#xff0c;作为跨境电商领域的佼佼者&#xff0c;凭借其深厚的行业经验和前瞻性的战略视野&#xff0c;在国际市场上展现出强大的竞争力&#xff0c;为行业的…