<!DOCTYPE html>
<html lang="en">
<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>
<style>
* {
box-sizing: border-box;
}
.slider {
width: 560px;
height: 400px;
overflow: hidden;
}
.slider-wrapper {
width: 100%;
height: 320px;
}
.slider-wrapper img {
width: 100%;
height: 100%;
display: block;
}
.slider-footer {
height: 80px;
background-color: rgb(100, 67, 68);
padding: 12px 12px 0 12px;
position: relative;
}
.slider-footer .toggle {
position: absolute;
right: 0;
top: 12px;
display: flex;
}
.slider-footer .toggle button {
margin-right: 12px;
width: 28px;
height: 28px;
appearance: none;
border: none;
background: rgba(255, 255, 255, 0.1);
color: #fff;
border-radius: 4px;
cursor: pointer;
}
.slider-footer .toggle button:hover {
background: rgba(255, 255, 255, 0.2);
}
.slider-footer p {
margin: 0;
color: #fff;
font-size: 18px;
margin-bottom: 10px;
}
.slider-indicator {
margin: 0;
padding: 0;
list-style: none;
display: flex;
align-items: center;
}
.slider-indicator li {
width: 8px;
height: 8px;
margin: 4px;
border-radius: 50%;
background: #fff;
opacity: 0.4;
cursor: pointer;
}
.slider-indicator li.active {
width: 12px;
height: 12px;
opacity: 1;
}
</style>
</head>
<body>
<div class="slider">
<div class="slider-wrapper">
<a href="#"><img src="./images/slider01.jpg" alt="" /></a>
</div>
<div class="slider-footer">
<p>对人类来说会不会太超前了?</p>
<ul class="slider-indicator">
<li class="active"></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
<div class="toggle">
<button class="prev"><</button>
<button class="next">></button>
</div>
</div>
</div>
<script>
// 1. 初始数据
const sliderData = [{
url: './images/slider01.jpg',
title: '对人类来说会不会太超前了?',
color: 'rgb(100, 67, 68)',
link: './index1.html'
},
{
url: './images/slider02.jpg',
title: '开启剑与雪的黑暗传说!',
color: 'rgb(43, 35, 26)',
link: './index2.html'
},
{
url: './images/slider03.jpg',
title: '真正的jo厨出现了!',
color: 'rgb(36, 31, 33)',
link: './index3.html'
},
{
url: './images/slider04.jpg',
title: '李玉刚:让世界通过B站看到东方大国文化',
color: 'rgb(139, 98, 66)',
link: './index4.html'
},
{
url: './images/slider05.jpg',
title: '快来分享你的寒假日常吧~',
color: 'rgb(67, 90, 92)',
link: './index5.html'
},
{
url: './images/slider06.jpg',
title: '哔哩哔哩小年YEAH',
color: 'rgb(166, 131, 143)',
link: './index6.html'
},
{
url: './images/slider07.jpg',
title: '一站式解决你的电脑配置问题!!!',
color: 'rgb(53, 29, 25)',
link: './index7.html'
},
{
url: './images/slider08.jpg',
title: '谁不想和小猫咪贴贴呢!',
color: 'rgb(99, 72, 114)',
link: './index8.html'
},
]
let intervalTime = 500
const next = document.querySelector('.next')
const img = document.querySelector('.slider-wrapper img')
const p = document.querySelector('.slider-footer p')
const a = document.querySelector('.slider-wrapper a')
let i = 0
next.addEventListener("click", function () {
i++
if (i >= sliderData.length) {
i = 0
}
load()
})
const prev = document.querySelector('.prev')
prev.addEventListener("click", function () {
i--
if (i < 0) {
i = sliderData.length - 1
}
load()
})
let timerId = setInterval(function () {
next.click()
}, intervalTime)
document.querySelector('.slider').addEventListener("mouseenter", function () {
clearInterval(timerId)
})
document.querySelector('.slider').addEventListener("mouseleave", function () {
clearInterval(timerId)
timerId = setInterval(function () {
next.click()
}, intervalTime)
})
function load() {
img.src = sliderData[i].url
p.innerHTML = sliderData[i].title
a.href = sliderData[i].link
document.querySelector('.slider-indicator .active').classList.remove('active')
document.querySelector(`.slider-indicator li:nth-child(${i+1})`).classList.add('active')
}
</script>
</body>
</html>
陪你听风
- 粉丝: 413
- 资源: 18
最新资源
- 基于java的预报名管理系统设计与实现.docx
- 基于java的在线骑行网站设计与实现.docx
- 基于java的在线租房招聘平台设计与实现.docx
- 基于java的在线环保网站设计与实现.docx
- 基于java的职业生涯规划系统设计与实现.docx
- 基于java的志愿服务管理系统设计与实现.docx
- 基于java的招生宣传管理系统设计与实现.docx
- 基于java的助农管理系统设计与实现.docx
- 基于java的足球俱乐部管理系统设计与实现.docx
- 基于java的足球社区管理系统设计与实现.docx
- 蓝牙串口助手,可以连接HC-05等蓝牙模块,实现单片机设备与手机通讯,安卓手机,蓝牙调试助手,具有按键功能!
- Java编程实现回文串检测技术及应用场景
- Java编程基础:常见算法及核心概念详解
- ZendFramework配置中文最新版本
- Linux客户端-eeba7-main.zip
- 基于java+springboot+vue+mysql的校园二手物品交易平台管理系统设计与实现.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈