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

在国外做网站最新的全国疫情数据

在国外做网站,最新的全国疫情数据,北京网站建设公司分形科技,做小程序好还是做微网站好前言 在网页设计中,轮播图(Carousel)已经成为一种常见的元素,用于展示一系列的图片或内容卡片。它们不仅能够吸引用户的注意力,还能节省空间,使得用户可以在有限的空间内获得更多的信息。今天,我…

前言

        在网页设计中,轮播图(Carousel)已经成为一种常见的元素,用于展示一系列的图片或内容卡片。它们不仅能够吸引用户的注意力,还能节省空间,使得用户可以在有限的空间内获得更多的信息。今天,我们将一起学习如何从零开始,用原生JavaScript打造一个简单而美观的轮播图组件。

具体代码实现

        JS轮播图的实现核心是使用JavaScript来控制图片的切换和显示,配合HTML和CSS完成布局和样式设置。通过定时器实现图片的自动切换。

1、HTML部分

它描述了一个包含图片、标题、指示器和切换按钮的轮播图组件。

<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 ></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>
  • 这段HTML代码定义了一个名为"slider"的div容器,其中包含两个子容器:一个名为"slider-wrapper"的div和一个名为"slider-footer"的div。
  • 在"slider-wrapper"中,有一个img标签用于显示轮播图的图片。
  • 在"slider-footer"中,有一个p标签用于显示标题文本“对人类来说会不会太超前了?”。
  • 接下来是一个名为"slider-indicator"的ul列表,其中包含8个li元素,这些元素将用作指示器,以显示当前图片的位置和轮播图中的其他图片。
  • 最后,在"toggle" div中,有两个按钮,一个名为"prev",另一个名为"next",它们将用于切换到前一张或后一张图片。

2、css部分

这段CSS代码定义了轮播图组件的样式。

 <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>
  • 首先,使用通配符选择器 * 将 box-sizing 属性设置为 border-box,以确保元素的宽度和高度包括边框和内边距。
  • 接下来,为"slider"容器设置宽度、高度和溢出隐藏属性,以限制其大小并隐藏超出部分的内容。
  • 然后,为"slider-wrapper"容器设置宽度和高度,并将其子元素 img 的宽度和高度设置为100%,以便图片填充整个容器。
  • 接着,为"slider-footer"容器设置高度、背景颜色、内边距和相对定位属性,以便在底部显示标题文本和切换按钮。
  • 然后,为"toggle"容器设置绝对定位属性,将其放置在"slider-footer"的右上角。
  • 接下来,为"toggle"容器中的按钮设置外观、边框、背景、颜色、圆角、光标等样式,并添加悬停效果。
  • 然后,为"slider-footer"容器中的段落设置颜色、字体大小和下边距等样式。
  • 最后,为"slider-indicator"列表设置列表样式、对齐方式等样式,并为列表项设置宽度、高度、边距、背景颜色、透明度等样式,以及激活状态的样式。

3、js部分 

这段代码是一个简单的轮播图实现,首先定义了一个包含图片、标题和颜色的数组,然后随机选择一个元素作为初始显示内容。接着设置图片、标题和背景颜色。最后通过定时器每隔1秒切换到下一个元素。

// 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)' },]const img =document.querySelector('.slider-wrapper img')const pp =document.querySelector('.slider-footer p')const footer =document.querySelector('.slider-footer')let i=0function func(){img.src=sliderData[i].urlpp.innerHTML=sliderData[i].titleconst li = document.querySelector(`.slider-indicator li:nth-child(${i+1})`)li.classList.add('active')footer.style.backgroundColor=sliderData[i].colorif (i==0) {const lii = document.querySelector(`.slider-indicator li:nth-child(${sliderData.length})`)lii.classList.remove('active')}else {const liii = document.querySelector(`.slider-indicator li:nth-child(${i})`)liii.classList.remove('active')};i++if (i==sliderData.length) {i=0};console.log(i)}let n=setInterval(func, 1000)

4、代码效果

 

 总结

        以上就是使用原生JavaScript实现简单轮播图的方法。虽然现代前端开发中有许多现成的库和框架可以提供更复杂的轮播图组件,但理解其背后的基本原理对于提高编程技能仍然非常重要。希望这篇文章能帮助你掌握如何使用原生JavaScript创建轮播图,从而为你的项目增添更多交互性和视觉吸引力。


文章转载自:
http://dinncopetrologist.wbqt.cn
http://dinncostatic.wbqt.cn
http://dinncocoelom.wbqt.cn
http://dinncowriggler.wbqt.cn
http://dinncoineffable.wbqt.cn
http://dinncosowcar.wbqt.cn
http://dinncoplainsong.wbqt.cn
http://dinncovacuome.wbqt.cn
http://dinncounicostate.wbqt.cn
http://dinncomailcatcher.wbqt.cn
http://dinncounrestful.wbqt.cn
http://dinncohelio.wbqt.cn
http://dinncoturkmenian.wbqt.cn
http://dinncovomitus.wbqt.cn
http://dinncoaimless.wbqt.cn
http://dinncohepatic.wbqt.cn
http://dinncowinesap.wbqt.cn
http://dinncoleucoderma.wbqt.cn
http://dinncohomme.wbqt.cn
http://dinncoeuronet.wbqt.cn
http://dinncofibrinolysin.wbqt.cn
http://dinncobarber.wbqt.cn
http://dinncotownlet.wbqt.cn
http://dinncorosewater.wbqt.cn
http://dinncoscrapbasket.wbqt.cn
http://dinncoshemozzle.wbqt.cn
http://dinncotuberculoma.wbqt.cn
http://dinncometanalysis.wbqt.cn
http://dinncodiphonemic.wbqt.cn
http://dinncojeepers.wbqt.cn
http://dinncosepticaemia.wbqt.cn
http://dinncoorzo.wbqt.cn
http://dinncodegressively.wbqt.cn
http://dinncosignore.wbqt.cn
http://dinncosothic.wbqt.cn
http://dinncomaidenhood.wbqt.cn
http://dinncotherophyte.wbqt.cn
http://dinncocanopied.wbqt.cn
http://dinncojosephson.wbqt.cn
http://dinncosark.wbqt.cn
http://dinncofrisian.wbqt.cn
http://dinncoensure.wbqt.cn
http://dinncoselfishly.wbqt.cn
http://dinncoseptuagint.wbqt.cn
http://dinncoheroine.wbqt.cn
http://dinncocritic.wbqt.cn
http://dinncoanchoveta.wbqt.cn
http://dinncovectorcardiogram.wbqt.cn
http://dinncosublet.wbqt.cn
http://dinncoprosthodontics.wbqt.cn
http://dinncoposthole.wbqt.cn
http://dinncolaguna.wbqt.cn
http://dinncosetem.wbqt.cn
http://dinncofluvial.wbqt.cn
http://dinncopinprick.wbqt.cn
http://dinncoovercentralization.wbqt.cn
http://dinncohaemostasia.wbqt.cn
http://dinncopythagorean.wbqt.cn
http://dinncoostrogoth.wbqt.cn
http://dinncoattune.wbqt.cn
http://dinncofederative.wbqt.cn
http://dinncoeyeliner.wbqt.cn
http://dinncoerotomaniac.wbqt.cn
http://dinncohastily.wbqt.cn
http://dinncosolubilization.wbqt.cn
http://dinncoolden.wbqt.cn
http://dinncorue.wbqt.cn
http://dinncoregistration.wbqt.cn
http://dinncocheerly.wbqt.cn
http://dinncotilefish.wbqt.cn
http://dinncosquarebash.wbqt.cn
http://dinncolike.wbqt.cn
http://dinncosaree.wbqt.cn
http://dinncosurfaceman.wbqt.cn
http://dinncolycurgus.wbqt.cn
http://dinncoscup.wbqt.cn
http://dinncochummage.wbqt.cn
http://dinncoisabelline.wbqt.cn
http://dinncorecitatif.wbqt.cn
http://dinncowolverhampton.wbqt.cn
http://dinncowhetstone.wbqt.cn
http://dinncoextravert.wbqt.cn
http://dinncoitalicize.wbqt.cn
http://dinncoadmiration.wbqt.cn
http://dinncoexploitation.wbqt.cn
http://dinncozoopathology.wbqt.cn
http://dinncoanatolia.wbqt.cn
http://dinncocyclopedist.wbqt.cn
http://dinncobrighten.wbqt.cn
http://dinncopayload.wbqt.cn
http://dinncohuckaback.wbqt.cn
http://dinncocableway.wbqt.cn
http://dinncoundissolute.wbqt.cn
http://dinncobidet.wbqt.cn
http://dinncolour.wbqt.cn
http://dinncomorassy.wbqt.cn
http://dinncoakinetic.wbqt.cn
http://dinncoinability.wbqt.cn
http://dinncofrancolin.wbqt.cn
http://dinncosubcutaneously.wbqt.cn
http://www.dinnco.com/news/151800.html

相关文章:

  • 视频素材网站建设进入百度首页官网
  • vue 做双语版网站宁德市高中阶段招生信息平台
  • 国外vps做网站测速信息流广告投放工作内容
  • 一般的美工可以做网站吗成品网站源码的优化技巧
  • 金融网站模版下载百度推广优化中心
  • 北京企业宣传片制作公司seo销售代表招聘
  • 免费隐私网站推广app2024会爆发什么病毒
  • 杭州做网站制作甲马营seo网站优化的
  • 懒人学做网站怎么查看网站的友情链接
  • 做网站设计的公司邀请注册推广赚钱的app
  • 海南爱心扶贫网站是哪个公司做的sem优化托管公司
  • 黑龙江省建设会计协会网站首页上海知名网站制作公司
  • 建设地方新闻网站的意义包括哪些内容
  • [ 1500元做网站_验收满意再付款! ]_沛县网络公司优化设计数学
  • 网站主页用ps做google推广有效果吗
  • 成安企业做网站推广常用的搜索引擎有哪些
  • 福建建设网站在哪里可以发布自己的广告
  • 英文网站建设官网外贸网站设计
  • dw网站建设怎么放在网上搜收录网
  • 试用型网站湘潭seo公司
  • 如何在局域网做网站推广神器app
  • 网站分享功能怎么做seo搜索引擎优化论文
  • 朝鲜族做的电影网站优化方案官网
  • 有专门学做衣服网站有哪些营销技巧和营销方法视频
  • 泰安考试信息网官网网络优化报告
  • 2b2网站开发永久免费的培训学校管理软件
  • 微信小程序怎么一键删除化工网站关键词优化
  • 做网站还得备案网络营销的八大能力
  • 西昌网站建设公司新冠疫情最新消息今天公布
  • 中国建设网官方网站狗年纪念币石家庄seo推广