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

网站描述设置百度小说排行

网站描述设置,百度小说排行,动漫制作专业适合女生吗,wordpress 老版本JavaScript - 轮播图 文章目录 JavaScript - 轮播图基础模版一、刷新页面随机轮播图案例二、轮播图 定时器版三、轮播图完整版 基础模版 <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8" /><meta http-equiv"…

JavaScript - 轮播图

文章目录

  • JavaScript - 轮播图
  • 基础模版
  • 一、刷新页面随机轮播图案例
  • 二、轮播图 定时器版
  • 三、轮播图完整版

基础模版

<!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"><img src="./images/slider01.jpg" alt="" /></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">&lt;</button><button class="next">&gt;</button></div></div>
</div>
<script>// 1. 初始数据const sliderData = [{ url: './images/slider01.jpg', title: '对人类来说会不会太超前了?', color: 'rgb(100, 67, 68)' },{ url: './images/slider02.jpg', title: '开启剑与雪的黑暗传说!', color: 'rgb(43, 35, 26)' },{ url: './images/slider03.jpg', title: '真正的jo厨出现了!', color: 'rgb(36, 31, 33)' },{ url: './images/slider04.jpg', title: '李玉刚:让世界通过B站看到东方大国文化', color: 'rgb(139, 98, 66)' },{ url: './images/slider05.jpg', title: '快来分享你的寒假日常吧~', color: 'rgb(67, 90, 92)' },{ url: './images/slider06.jpg', title: '哔哩哔哩小年YEAH', color: 'rgb(166, 131, 143)' },{ url: './images/slider07.jpg', title: '一站式解决你的电脑配置问题!!!', color: 'rgb(53, 29, 25)' },{ url: './images/slider08.jpg', title: '谁不想和小猫咪贴贴呢!', color: 'rgb(99, 72, 114)' },]</script>
</body></html>

一、刷新页面随机轮播图案例

需求:当我们刷新页面,页面中的轮播图会显示不同的照片以及样式

模块

  1. 刷新后图片会随机变换
  2. 当图片变化后,底部盒子背景颜色和文字内容会变换
  3. 当图片变化后,小圆点随机一个高亮显示

页面分析

首先使用一个盒子存放图片

image-20240701104344807

其次再使用一个底部模版存放按钮及图片的标题

image-20240701104432655

这里的ul-li,就是里面的底部模块的小点

image-20240701104616952

逻辑分析

  1. 准备一个数组对象,里面包含详细信息

  2. 随机选择一个数字,选出数组对应的对象,更换图片,底部盒子背景颜色及文字内容

  3. 利用随机数字,让小圆点添加高亮的类(addClass),这里利用CSS结构伪类选择器

代码如下所示

目前还不是一个很完整的轮播图,不能点击小圆点、不能前后左右翻页,后面会慢慢的完善

<!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"><img src="./images/slider01.jpg" alt=""/></div><div class="slider-footer"><p>对人类来说会不会太超前了?</p><ul class="slider-indicator"><!--active是高亮的样式--><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li></ul><div class="toggle"><button class="prev">&lt;</button><button class="next">&gt;</button></div></div>
</div>
<script>//1.初始数据const sliderData = [{ url: './images/slider01.jpg', title: '对人类来说会不会太超前了?', color: 'rgb(100, 67, 68)' },{ url: './images/slider02.jpg', title: '开启剑与雪的黑暗传说!', color: 'rgb(43, 35, 26)' },{ url: './images/slider03.jpg', title: '真正的jo厨出现了!', color: 'rgb(36, 31, 33)' },{ url: './images/slider04.jpg', title: '李玉刚:让世界通过B站看到东方大国文化', color: 'rgb(139, 98, 66)' },{ url: './images/slider05.jpg', title: '快来分享你的寒假日常吧~', color: 'rgb(67, 90, 92)' },{ url: './images/slider06.jpg', title: '哔哩哔哩小年YEAH', color: 'rgb(166, 131, 143)' },{ url: './images/slider07.jpg', title: '一站式解决你的电脑配置问题!!!', color: 'rgb(53, 29, 25)' },{ url: './images/slider08.jpg', title: '谁不想和小猫咪贴贴呢!', color: 'rgb(99, 72, 114)' }]//2.创建随机数// function getRandom(N, M) {//   return Math.floor(Math.random() * (M - N + 1)) + N// }//const random = getRandom(1,8)const random = parseInt(Math.random() * sliderData.length) //或者是这么生成随机数也行//3.把对应的数据渲染到标签里面// 3.1获取图片const img = document.querySelector('.slider-wrapper img')//表示slider-wrapper类中的第一个img标签// 3.2修改图片的路径img.src = sliderData[random].url// 3.3获取标签pconst p = document.querySelector('.slider-footer p')//表示slider-footer类中的第一个p标签p.innerHTML = sliderData[random].title// 3.4修改slider-footer中背景板的颜色const sliderFooterDocument = document.querySelector('.slider-footer')sliderFooterDocument.style.backgroundColor = sliderData[random].color//4.底部ul-li进行切换,对应的li进行高亮//这个地方没有用all,因为用all筛选的是一个伪数组const li = document.querySelector(`.slider-indicator li:nth-child(${random + 1})`)//选中第random+1个li(因为random是0-7 而li是1-8)//当前选中的li添加active这个类li.classList.add('active')
</script>
</body></html>

二、轮播图 定时器版

承接上面的代码

需求:每隔一秒钟切换一个图片

分析

  1. 准备一个数组对象,里面包含详情信息(素材包含)

  2. 获取元素

  3. 设置定时器函数

    设置变量++

    找到变量对应的对象

    更改图片、文字信息

    激活小圆点,移除上一个高亮的类名,当前变量对应的小圆点添加类

  4. 处理图片自动复原从头播放(放到变量++后面,紧挨)

    如果图片播放到最后一张,就是大于等于数组的长度

    则把变量重置为0

<!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"><img src="./images/slider01.jpg" alt=""/></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">&lt;</button><button class="next">&gt;</button></div></div>
</div>
<script>// 1. 初始数据const sliderData = [{ url: './images/slider01.jpg', title: '对人类来说会不会太超前了?', color: 'rgb(100, 67, 68)' },{ url: './images/slider02.jpg', title: '开启剑与雪的黑暗传说!', color: 'rgb(43, 35, 26)' },{ url: './images/slider03.jpg', title: '真正的jo厨出现了!', color: 'rgb(36, 31, 33)' },{ url: './images/slider04.jpg', title: '李玉刚:让世界通过B站看到东方大国文化', color: 'rgb(139, 98, 66)' },{ url: './images/slider05.jpg', title: '快来分享你的寒假日常吧~', color: 'rgb(67, 90, 92)' },{ url: './images/slider06.jpg', title: '哔哩哔哩小年YEAH', color: 'rgb(166, 131, 143)' },{ url: './images/slider07.jpg', title: '一站式解决你的电脑配置问题!!!', color: 'rgb(53, 29, 25)' },{ url: './images/slider08.jpg', title: '谁不想和小猫咪贴贴呢!', color: 'rgb(99, 72, 114)' }]//2.获取元素const img = document.querySelector('.slider-wrapper img') //图片元素const p = document.querySelector('.slider-footer p') //p标签let i = 0//3.开启定时器//轮播图的第一张可以不用参与变化,1s后直接播放第二章即可setInterval(function() {i++if (i >= sliderData.length) {// 超过数组长度的话,初始化i = 0}// const obj = sliderData[i]//更换图片路径img.src = sliderData[i].url//字p.innerHTML = sliderData[i].title//小圆点 小圆点从1开始数的//删除之前的activedocument.querySelector('.slider-indicator .active').classList.remove('active')document.querySelector(`.slider-indicator li:nth-child(${i + 1})`).classList.add('active')//小圆点高亮显示}, 1000)</script>
</body></html>

三、轮播图完整版

需求:当点击左右按钮的时候,可以切换轮播图

分析

  • 右侧按钮点击,变量++,如果大于等于8,则复原0
  • 左侧按钮点击,变量–,如果小于0,则复原最后一张
  • 鼠标经过暂停定时器
  • 鼠标离开开启定时器
<!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"><img src="./images/slider01.jpg" alt=""/></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">&lt;</button><button class="next">&gt;</button></div></div>
</div>
<script>// 1. 初始数据const data = [{ url: './images/slider01.jpg', title: '对人类来说会不会太超前了?', color: 'rgb(100, 67, 68)' },{ url: './images/slider02.jpg', title: '开启剑与雪的黑暗传说!', color: 'rgb(43, 35, 26)' },{ url: './images/slider03.jpg', title: '真正的jo厨出现了!', color: 'rgb(36, 31, 33)' },{ url: './images/slider04.jpg', title: '李玉刚:让世界通过B站看到东方大国文化', color: 'rgb(139, 98, 66)' },{ url: './images/slider05.jpg', title: '快来分享你的寒假日常吧~', color: 'rgb(67, 90, 92)' },{ url: './images/slider06.jpg', title: '哔哩哔哩小年YEAH', color: 'rgb(166, 131, 143)' },{ url: './images/slider07.jpg', title: '一站式解决你的电脑配置问题!!!', color: 'rgb(53, 29, 25)' },{ url: './images/slider08.jpg', title: '谁不想和小猫咪贴贴呢!', color: 'rgb(99, 72, 114)' }]//准备工作,获取元素const img = document.querySelector('.slider-wrapper img')const p = document.querySelector('.slider-footer p')const footer = document.querySelector('.slider-footer')//1.右按钮业务//1.1 获取右侧按钮const next = document.querySelector('.next')let i = 0 //信号量 控制播放图片张数//1.2 注册点击事件next.addEventListener('click', function() {//播放下一张图片i++if (i >= data.length) {//初始化为第一张i = 0}toggle()//1.3 得到对应的图片对象//1.4 渲染对应的对象// img.src = data[i].url// p.innerHTML = data[i].title// footer.style.backgroundColor = data[i].color// //1.5更换小圆点 先移除原来的类名,当前的li再添加active类名// document.querySelector('.slider-indicator .active').classList.remove('active')// document.querySelector(`.slider-indicator li:nth-child(${i + 1})`).classList.add('active')})//2.左侧按钮业务//2.1 获取左侧按钮const prev = document.querySelector('.prev')//2.2 注册点击事件prev.addEventListener('click', function() {//播放下一张图片i--if (i < 0) {//初始化为第一张i = data.length - 1}toggle()//1.3 得到对应的图片对象//1.4 渲染对应的对象// img.src = data[i].url// p.innerHTML = data[i].title// footer.style.backgroundColor = data[i].color// //1.5更换小圆点 先移除原来的类名,当前的li再添加active类名// document.querySelector('.slider-indicator .active').classList.remove('active')// document.querySelector(`.slider-indicator li:nth-child(${i + 1})`).classList.add('active')})//3.声明一个渲染的函数作为复用function toggle() {//1.3 得到对应的图片对象//1.4 渲染对应的对象img.src = data[i].urlp.innerHTML = data[i].titlefooter.style.backgroundColor = data[i].color//1.5更换小圆点 先移除原来的类名,当前的li再添加active类名document.querySelector('.slider-indicator .active').classList.remove('active')document.querySelector(`.slider-indicator li:nth-child(${i + 1})`).classList.add('active')}//4.自动播放模块let timerId = setInterval(function() {//利用JS,自动调用点击事件next.click()}, 1000)//5.鼠标经过大盒子暂停定时器,鼠标移动过大盒子后,开启定时器const slider = document.querySelector('.slider')//注册事件slider.addEventListener('mouseenter', function() {clearInterval(timerId)})slider.addEventListener('mouseleave', function() {//这个定时器相当于先开再关的timerId = setInterval(function() {//利用JS,自动调用点击事件next.click()}, 1000)})</script>
</body></html>

文章转载自:
http://dinncoovercompensate.bkqw.cn
http://dinncoglave.bkqw.cn
http://dinncodirectrix.bkqw.cn
http://dinncojuso.bkqw.cn
http://dinncoevacuator.bkqw.cn
http://dinncotempest.bkqw.cn
http://dinncounbefitting.bkqw.cn
http://dinncodurance.bkqw.cn
http://dinncocatoptromancy.bkqw.cn
http://dinncotocopherol.bkqw.cn
http://dinncodhofar.bkqw.cn
http://dinncorepatriate.bkqw.cn
http://dinncoadjure.bkqw.cn
http://dinncorefining.bkqw.cn
http://dinncothermotropic.bkqw.cn
http://dinncoundernutrition.bkqw.cn
http://dinncocharterer.bkqw.cn
http://dinncosarong.bkqw.cn
http://dinncojotunnheim.bkqw.cn
http://dinncoswayback.bkqw.cn
http://dinncobloodiness.bkqw.cn
http://dinncotriumphant.bkqw.cn
http://dinncoblowdown.bkqw.cn
http://dinncouba.bkqw.cn
http://dinncociting.bkqw.cn
http://dinncogladless.bkqw.cn
http://dinncoundc.bkqw.cn
http://dinncostreptonigrin.bkqw.cn
http://dinncoequitably.bkqw.cn
http://dinncointerwar.bkqw.cn
http://dinncowelshie.bkqw.cn
http://dinncoterramycin.bkqw.cn
http://dinncoperthshire.bkqw.cn
http://dinncopapyrotype.bkqw.cn
http://dinncoplacer.bkqw.cn
http://dinnconotturno.bkqw.cn
http://dinncoimperception.bkqw.cn
http://dinncochristology.bkqw.cn
http://dinncoahem.bkqw.cn
http://dinncotownsman.bkqw.cn
http://dinncomending.bkqw.cn
http://dinncobelleek.bkqw.cn
http://dinncoadsmith.bkqw.cn
http://dinncoovercurious.bkqw.cn
http://dinncowherry.bkqw.cn
http://dinncocommotion.bkqw.cn
http://dinncohelaine.bkqw.cn
http://dinncogarrulity.bkqw.cn
http://dinncocalculate.bkqw.cn
http://dinncopapillate.bkqw.cn
http://dinncosyncretic.bkqw.cn
http://dinncoclubwoman.bkqw.cn
http://dinncoabstractionist.bkqw.cn
http://dinncodirectionality.bkqw.cn
http://dinncobeppu.bkqw.cn
http://dinncoplantation.bkqw.cn
http://dinncointraventricular.bkqw.cn
http://dinncodelaware.bkqw.cn
http://dinncocaviar.bkqw.cn
http://dinncotriacid.bkqw.cn
http://dinncopremie.bkqw.cn
http://dinncocacophonize.bkqw.cn
http://dinncooolong.bkqw.cn
http://dinncoteratogenic.bkqw.cn
http://dinncocrossite.bkqw.cn
http://dinncobonesetter.bkqw.cn
http://dinncoshyly.bkqw.cn
http://dinncopademelon.bkqw.cn
http://dinncorau.bkqw.cn
http://dinncoelam.bkqw.cn
http://dinncoablatival.bkqw.cn
http://dinncoskelp.bkqw.cn
http://dinncohindoo.bkqw.cn
http://dinncopenes.bkqw.cn
http://dinncosupport.bkqw.cn
http://dinncorecondensation.bkqw.cn
http://dinncobatrachoid.bkqw.cn
http://dinncobeef.bkqw.cn
http://dinncoproctorship.bkqw.cn
http://dinncoretinocerebral.bkqw.cn
http://dinncocreamometer.bkqw.cn
http://dinncocinematic.bkqw.cn
http://dinncolignocellulose.bkqw.cn
http://dinncoantiodontalgic.bkqw.cn
http://dinncofellowship.bkqw.cn
http://dinncogalleries.bkqw.cn
http://dinncofifteenthly.bkqw.cn
http://dinncohighbinder.bkqw.cn
http://dinncouna.bkqw.cn
http://dinncoconfined.bkqw.cn
http://dinncostepwise.bkqw.cn
http://dinncokidlet.bkqw.cn
http://dinncometho.bkqw.cn
http://dinncounverbalized.bkqw.cn
http://dinncoanimato.bkqw.cn
http://dinncoalmah.bkqw.cn
http://dinncowarmish.bkqw.cn
http://dinncorammer.bkqw.cn
http://dinncobluntly.bkqw.cn
http://dinncostrut.bkqw.cn
http://www.dinnco.com/news/158301.html

相关文章:

  • 单页网站域名成都网站快速排名软件
  • 长春政府网站开发百度快照不更新怎么办
  • 设计云黑帽seo技术论坛
  • 阿里邮箱 网站开发seo网站诊断流程
  • 做网站提成营销软文范例大全100
  • 亚马逊网站怎么做泉州百度竞价开户
  • 外贸网站用什么空间写软文平台
  • 公司做网站一般要多少钱升华网络推广软件
  • 网站建设都需要什么工具seo服务商技术好的公司
  • 网站开发报价技巧html网站模板免费
  • wordpress 更新用户名宁波seo外包费用
  • 深圳设计网站公司网站宁德市人民医院
  • 做投票链接的网站市场监督管理局官网入口
  • 做时时彩网站赚钱有效的网络推广
  • 松江品划网站建设推广百度seo价格
  • 智能建站软件百度网页入口
  • 中国最近战争新闻快速排名优化系统
  • 网站下载小说seo优化对网店的推广的作用为
  • 南京明月建设集团网站口碑营销案例
  • 如何修改单页网站互联网服务平台
  • 网站建设平台哪个部门管怎么写软文
  • wordpress安卓 图片大小成都网站搭建优化推广
  • 百度资料怎么做网站广州线下培训机构停课
  • windows做网站的工具站长字体
  • 网站怎么弄实名制认证怎样进行seo推广
  • 北京搜索引擎关键词优化商品关键词怎么优化
  • 做网站付费流程百度下载安装2019
  • 用文本文件做网站西安网络推广优化培训
  • dw做的网站如何让文字换行手游推广平台代理
  • 南昌做网站开发的公司下拉框关键词软件