html+js 轮播图

devtools/2025/3/9 21:44:07/
htmledit_views">

html"><!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>轮播图示例</title><style>/* 基本样式 */body {margin: 0;padding: 0;display: flex;justify-content: center;align-items: center;height: 100vh;background-color: #f0f0f0;font-family: Arial, sans-serif;}/* 轮播图容器 */.carousel {width: 600px;height: 400px;position: relative;overflow: hidden;border-radius: 10px;box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);}/* 图片容器 */.carousel-images {display: flex;width: 100%;height: 100%;transition: transform 0.5s ease-in-out;}/* 图片样式 */.carousel-images img {width: 100%;height: 100%;object-fit: cover;flex-shrink: 0;}/* 左右按钮 */.carousel-button {position: absolute;top: 50%;transform: translateY(-50%);background-color: rgba(0, 0, 0, 0.5);color: white;border: none;padding: 10px;cursor: pointer;font-size: 18px;border-radius: 50%;transition: background-color 0.3s ease;}.carousel-button:hover {background-color: rgba(0, 0, 0, 0.8);}/* 左按钮 */.carousel-button.prev {left: 10px;}/* 右按钮 */.carousel-button.next {right: 10px;}/* 指示器容器 */.carousel-indicators {position: absolute;bottom: 10px;left: 50%;transform: translateX(-50%);display: flex;gap: 5px;}/* 指示器样式 */.carousel-indicators span {width: 10px;height: 10px;background-color: rgba(255, 255, 255, 0.5);border-radius: 50%;cursor: pointer;transition: background-color 0.3s ease;}.carousel-indicators span.active {background-color: white;}</style>
</head>
<body><!-- 轮播图容器 --><div class="carousel"><!-- 图片容器 --><div class="carousel-images"><img src="https://image.meiye.art/pic_1631411429199mjIE7yxqjZxWNdOvWLxL2?imageMogr2/thumbnail/640x/interlace/1" alt="Image 1"><img src="https://image.meiye.art/pic_16324946992753vSLEv0P2s-1PY95ynOZn?imageMogr2/thumbnail/640x/interlace/1" alt="Image 2"><img src="https://image.meiye.art/pic_1628403749737?imageMogr2/thumbnail/640x/interlace/1" alt="Image 3"></div><!-- 左右按钮 --><button class="carousel-button prev">&lt;</button><button class="carousel-button next">&gt;</button><!-- 指示器 --><div class="carousel-indicators"><span class="active"></span><span></span><span></span></div></div><script>// 获取元素const carouselImages = document.querySelector('.carousel-images');const prevButton = document.querySelector('.carousel-button.prev');const nextButton = document.querySelector('.carousel-button.next');const indicators = document.querySelectorAll('.carousel-indicators span');let currentIndex = 0; // 当前显示的图片索引const totalImages = carouselImages.children.length; // 图片总数// 更新指示器状态function updateIndicators() {indicators.forEach((indicator, index) => {indicator.classList.toggle('active', index === currentIndex);});}// 切换到指定图片function goToImage(index) {if (index < 0) {index = totalImages - 1; // 如果小于0,切换到最后一张} else if (index >= totalImages) {index = 0; // 如果超出范围,切换到第一张}currentIndex = index;carouselImages.style.transform = `translateX(-${currentIndex * 100}%)`;updateIndicators();}// 切换到上一张图片prevButton.addEventListener('click', () => {goToImage(currentIndex - 1);});// 切换到下一张图片nextButton.addEventListener('click', () => {goToImage(currentIndex + 1);});// 点击指示器切换图片indicators.forEach((indicator, index) => {indicator.addEventListener('click', () => {goToImage(index);});});// 自动播放let autoPlayInterval = setInterval(() => {goToImage(currentIndex + 1);}, 3000);// 鼠标悬停时停止自动播放const carousel = document.querySelector('.carousel');carousel.addEventListener('mouseenter', () => {clearInterval(autoPlayInterval);});// 鼠标离开时恢复自动播放carousel.addEventListener('mouseleave', () => {autoPlayInterval = setInterval(() => {goToImage(currentIndex + 1);}, 3000);});</script>
</body>
</html>


http://www.ppmy.cn/devtools/165857.html

相关文章

PythonCrowler

requests模块 python中原生的一款基于网络请求的模块,作用是模拟浏览器发送请求 指定url-发送请求-获取响应数据-持久化存储 pro1:爬取搜狗首页的页面数据 basic crowler import requests if __name__ __main__:urlhttps://www.sogou.comresrequests.get(url)page_datare…

游戏元宇宙崛起:AI代理IP驱动虚拟世界“无限可能”​

在科技飞速发展的当下&#xff0c;游戏元宇宙正以一种前所未有的姿态崛起&#xff0c;它犹如一颗璀璨的新星&#xff0c;吸引着无数人的目光。而AI代理IP&#xff0c;正成为驱动这个虚拟世界展现“无限可能”的关键力量。 「快代理&#xff5c;11年专注企业级代理IP云服务 —…

Redis 日常运维与故障处理

Redis 日常运维与故障处理 Redis 作为一个高性能的键值存储系统,被广泛应用于缓存、消息队列、排行榜等场景。为了确保 Redis 的稳定运行和高效性能,日常运维和故障处理至关重要。本文将详细介绍 Redis 的日常运维任务、常见故障及其解决方法,帮助运维人员有效管理和维护 R…

游戏引擎学习第140天

回顾并为今天的内容做准备 目前代码的进展到了声音混音的部分。昨天我详细解释了声音的处理方式&#xff0c;声音在技术上是一个非常特别的存在&#xff0c;但在游戏中进行声音混音的需求其实相对简单明了&#xff0c;所以今天的任务应该不会太具挑战性。 今天我们会编写一个…

yum修改阿里云

第一步&#xff1a;打开FinalShell&#xff0c;点击haodoop100&#xff0c;输入命令&#xff1a; sudo curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo 第二步&#xff1a;继续输入命令&#xff1a;sudo yum clean all …

安铂克科技 APPH 系列相位噪声分析仪:高性能测量的卓越之选

在当今的电子测量领域&#xff0c;对于信号源及各类设备的精确评估至关重要。安铂克科技的 APPH 系列相位噪声分析仪&#xff08;亦称作相噪仪、相位噪声测量仪、信号源分析仪&#xff09;&#xff0c;凭借其超凡的性能与全面的功能&#xff0c;成为众多工程师与科研人员的理想…

分布式锁—4.Redisson的联锁和红锁二

大纲 1.Redisson联锁MultiLock概述 2.Redisson联锁MultiLock的加锁与释放锁 3.Redisson红锁RedLock的算法原理 4.Redisson红锁RedLock的源码分析 3.Redisson红锁RedLock的算法原理 (1)RedLock算法的具体流程 (2)RedLock算法的四个要点总结 (1)RedLock算法的具体流程 步骤…

VSCode详细安装步骤,适用于 Windows/macOS/Linux 系统

以下是 Visual Studio Code (VSCode) 的详细安装步骤&#xff0c;适用于 Windows/macOS/Linux 系统&#xff1a; VSCode 的详细安装步骤 一、Windows 系统安装1. 下载安装包2. 运行安装程序3. 验证安装 二、macOS 系统安装1. 方法一&#xff1a;官网下载安装包2. 方法二&#x…