news 2026/6/9 21:35:00

134-136 完成轮播图界面,完成点击按钮切换图片,完成轮播图

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
134-136 完成轮播图界面,完成点击按钮切换图片,完成轮播图

完成轮播图界面,完成点击按钮切换图片,完成轮播图

<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>4张图片轮播图</title> <style> * { margin: 0; padding: 0; box-sizing: border-box; } /* 轮播图容器 */ .carousel-container { position: relative; width: 450px; height: 450px; margin: 50px auto; overflow: hidden; border-radius: 10px; box-shadow: 0 0 20px rgba(0,0,0,0.2); } /* 图片轮播列表 */ .carousel-list { display: flex; width: 400%; /* 4张图片,所以宽度为400% */ height: 100%; transition: transform 0.5s ease; } .carousel-item { width: 100%; height: 100%; } .carousel-item img { width: 100%; height: 100%; object-fit: cover; } /* 左右切换按钮 */ .carousel-btn { position: absolute; top: 50%; transform: translateY(-50%); width: 40px; height: 40px; background-color: rgba(255,255,255,0.7); border: none; border-radius: 50%; font-size: 20px; cursor: pointer; display: flex; align-items: center; justify-content: center; z-index: 10; transition: background-color 0.3s; } .carousel-btn:hover { background-color: rgba(255,255,255,1); } .prev-btn { left: 20px; } .next-btn { right: 20px; } /* 页码指示器 */ .carousel-indicators { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; gap: 10px; } .indicator-btn { width: 12px; height: 12px; border-radius: 50%; border: none; background-color: rgba(255,255,255,0.5); cursor: pointer; transition: background-color 0.3s, transform 0.3s; } .indicator-btn.active { background-color: #ffffff; transform: scale(1.2); } </style> </head> <body> <div class="carousel-container" id="carousel"> <!-- 轮播图片列表 --> <div class="carousel-list" id="carouselList"> <div class="carousel-item"> <img src="./img/1.jpg" alt="轮播图1"> </div> <div class="carousel-item"> <img src="./img/2.jpg" alt="轮播图2"> </div> <div class="carousel-item"> <img src="./img/3.jpg" alt="轮播图3"> </div> <div class="carousel-item"> <img src="./img/4.jpg" alt="轮播图4"> </div> </div> <!-- 左右切换按钮 --> <button class="carousel-btn prev-btn" id="prevBtn">&lt;</button> <button class="carousel-btn next-btn" id="nextBtn">&gt;</button> <!-- 页码指示器 --> <div class="carousel-indicators" id="indicators"></div> </div> <script> // 获取DOM元素 const carousel = document.getElementById('carousel'); const carouselList = document.getElementById('carouselList'); const prevBtn = document.getElementById('prevBtn'); const nextBtn = document.getElementById('nextBtn'); const indicators = document.getElementById('indicators'); // 轮播图配置 const imgCount = 4; // 图片数量 let currentIndex = 0; // 当前显示的图片索引 let autoPlayTimer = null; // 自动轮播定时器 const autoPlayInterval = 3000; // 自动轮播间隔(毫秒) // 生成页码指示器按钮 function createIndicators() { for (let i = 0; i < imgCount; i++) { const btn = document.createElement('button'); btn.className = 'indicator-btn'; if (i === 0) btn.classList.add('active'); // 初始第一个按钮激活 btn.dataset.index = i; // 存储索引数据 // 点击页码按钮切换图片 btn.addEventListener('click', () => { currentIndex = i; updateCarousel(); }); indicators.appendChild(btn); } } // 更新轮播图显示和页码状态 function updateCarousel() { // 计算偏移量,移动图片列表 const offset = -currentIndex * (100 / imgCount); carouselList.style.transform = `translateX(${offset}%)`; // 更新页码按钮激活状态 const indicatorBtns = document.querySelectorAll('.indicator-btn'); indicatorBtns.forEach((btn, index) => { if (index === currentIndex) { btn.classList.add('active'); } else { btn.classList.remove('active'); } }); } // 上一张 function prevImg() { currentIndex = (currentIndex - 1 + imgCount) % imgCount; updateCarousel(); } // 下一张 function nextImg() { currentIndex = (currentIndex + 1) % imgCount; updateCarousel(); } // 启动自动轮播 function startAutoPlay() { autoPlayTimer = setInterval(nextImg, autoPlayInterval); } // 停止自动轮播 function stopAutoPlay() { clearInterval(autoPlayTimer); } // 初始化 function initCarousel() { createIndicators(); // 创建页码按钮 startAutoPlay(); // 启动自动轮播 // 绑定左右按钮事件 prevBtn.addEventListener('click', prevImg); nextBtn.addEventListener('click', nextImg); // 鼠标悬停暂停轮播,离开继续 carousel.addEventListener('mouseenter', stopAutoPlay); carousel.addEventListener('mouseleave', startAutoPlay); } // 页面加载完成后初始化轮播图 window.addEventListener('DOMContentLoaded', initCarousel); </script> </body> </html>

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/6/10 12:12:20

LangGraph内存架构全解析:构建能记住过去的AI智能体实战指南

本文详细介绍了如何使用LangGraph构建具有持久记忆能力的AI智能体。通过分析LangGraph的双系统记忆架构&#xff08;短期记忆和长期记忆&#xff09;&#xff0c;讲解了记忆专用节点设计、优化策略及常见问题解决方案。文章强调了State作为记忆流转中枢、专用记忆节点实现闭环操…

作者头像 李华
网站建设 2026/6/9 23:23:37

揭秘大模型背后的“特级教师“:数据标注员的前世今生与未来

收藏&#xff01;揭秘大模型背后的"特级教师"&#xff1a;数据标注员的前世今生与未来 数据标注员作为AI的"老师"&#xff0c;正从低端重复工作向高端化转变&#xff0c;头部大模型公司积极招募高学历人才。尽管面临缺乏尊严、性价比低、上升空间狭窄等问题…

作者头像 李华
网站建设 2026/6/10 10:46:04

doris的导入数据库文件的的同步导入方式

DorisDB&#xff08;原Apache Doris&#xff09;支持多种数据导入方式&#xff0c;其中同步导入通常指通过**INSERT INTO语句**实现单条或小批量数据的实时写入。以下是关键特性及示例&#xff1a;一、INSERT INTO同步导入核心特性事务性保证通过MySQL协议提交的INSERT操作具备…

作者头像 李华
网站建设 2026/6/10 10:41:31

西门子博途TSEND_C与TRCV_C通信编程实例

VoxCPM-1.5-TTS-WEB-UI 文本转语音大模型部署与推理实战 在智能交互系统日益普及的今天&#xff0c;高质量语音合成已不再是实验室里的“黑科技”&#xff0c;而是工业自动化、无障碍服务、虚拟人系统中不可或缺的一环。传统TTS方案常受限于语调机械、延迟高、部署复杂等问题&…

作者头像 李华
网站建设 2026/6/10 3:08:40

Windows下TensorFlow-GPU的C++库编译指南

Windows环境下编译TensorFlow 2.9 GPU版C库的完整实践 在工业级AI部署场景中&#xff0c;越来越多项目需要摆脱Python解释器的依赖&#xff0c;转而采用原生C实现高性能推理。尤其是在边缘设备、实时检测系统或高并发服务中&#xff0c;直接调用TensorFlow C API不仅能显著降低…

作者头像 李华
网站建设 2026/6/10 11:54:54

WGS84转CGCS2000坐标系操作步骤详解

WGS84转CGCS2000坐标系操作全解析 在测绘、国土调查和城市规划的实际工作中&#xff0c;经常会遇到一个看似简单却极易出错的问题&#xff1a;如何将GPS采集的WGS84坐标准确转换为符合国家标准的CGCS2000坐标&#xff1f;很多人以为这两个坐标系“差不多”&#xff0c;可以直接…

作者头像 李华