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

河南移动商城网站建设今日最新国际新闻

河南移动商城网站建设,今日最新国际新闻,app设计总结,四川省住建厅官网随着互联网的发展,网站的界面设计越来越重要。吸引用户的关注、提高用户体验已经成为了许多网站的目标。而在实现各种复杂的界面效果中,CSS与JS的组合无疑是开发者的得力工具。本文将介绍如何使用CSS和JS实现一个响应式的滚动时间轴。 1.需求分析 在开…

随着互联网的发展,网站的界面设计越来越重要。吸引用户的关注、提高用户体验已经成为了许多网站的目标。而在实现各种复杂的界面效果中,CSS与JS的组合无疑是开发者的得力工具。本文将介绍如何使用CSS和JS实现一个响应式的滚动时间轴。

1.需求分析

在开始实现之前,我们需要分析出需求。首先,我们需要一个时间轴的框架,其中包含一系列的事件节点,这些事件节点可以根据滚动条的位置来进行滚动。其次,在滚动条滚动期间,我们需要将当前事件节点高亮显示,以便用户更好地了解当前所处的时间位置。最后,如果用户拖拽滚动条时,我们需要平滑地接过控制权,并根据滚动条位置来定位事件节点。

2.准备工作

在开始实现之前,我们需要做一些准备工作。首先,我们需要准备好HTML结构,包括时间轴框架、事件节点等元素;其次,我们需要使用CSS样式来美化这些元素,并且确保它们能正确地显示在页面上;最后,我们需要使用JS来控制滚动条的位置并根据其位置来定位事件节点。下面是我们需要准备的HTML结构:

<div class="timeline__container"> <div class="timeline__track"> <ul class="timeline__events"> <li class="timeline__event" style="left: 0;"> <div class="timeline__event_title">Event 1</div> <div class="timeline__event_date">2023-05-03</div> </li> <li class="timeline__event" style="left: 20%;"> <div class="timeline__event_title">Event 2</div> <div class="timeline__event_date">2023-05-04</div> </li> <li class="timeline__event" style="left: 40%;"> <div class="timeline__event_title">Event 3</div> <div class="timeline__event_date">2023-05-05</div> </li> <li class="timeline__event" style="left: 60%;"> <div class="timeline__event_title">Event 4</div> <div class="timeline__event_date">2023-05-06</div> </li> <li class="timeline__event" style="left: 80%;"> <div class="timeline__event_title">Event 5</div> <div class="timeline__event_date">2023-05-07</div> </li> </ul> <div class="timeline__scrollbar"> <div class="timeline__thumb"></div> </div> </div> </div>

这段代码中,我们使用了一个div元素来作为时间轴的容器,其中包含了一个div元素作为时间轴的轨道。轨道中包含了一个无序列表ul,其中的每个列表项li代表一个事件节点。每个事件节点中包含了一个标题和日期。最后,我们还需要一个滚动条以便用户进行滚动。

接下来,我们需要使用CSS样式来美化这些元素并确保它们能正确地显示在页面上。

.timeline__container { width: 100%; height: 500px; position: relative; } .timeline__track { width: 80%; height: 500px; background-color: #fff; margin: 0 auto; position: relative; overflow-x: hidden; } .timeline__events { display: flex; position: absolute; top: 50%; transform: translateY(-50%); left: 0; margin: 0; padding: 0; width: 100%; } .timeline__event { width: 20%; height: 80%; margin: 0; padding: 0; position: relative; list-style: none; cursor: pointer; transition: all 0.3s ease-in-out; z-index: 1; text-align: center; } .timeline__event_title { font-size: 18px; font-weight: bold; margin-bottom: 10px; } .timeline__event_date { font-size: 14px; } .timeline__event::before { content: ""; display: block; position: absolute; top: 50%; transform: translateY(-50%); left: -5px; width: 10px; height: 10px; border-radius: 50%; background-color: #fff; border: 3px solid #000; z-index: 2; } .timeline__event:hover { transform: scale(1.2); z-index: 3; } .timeline__event.active { transform: scale(1.2); z-index: 3; } .timeline__scrollbar { position: absolute; bottom: 0; left: 0; width: 100%; height: 20px; background-color: #eee; } .timeline__thumb { position: absolute; top: 0; left: 0; width: 20%; height: 100%; background-color: #ccc; cursor: pointer; }

这段代码中,我们设置了时间轴容器的宽高和位置相关属性。其中轨道的宽度为80%,高度为500px,并且在水平方向上隐藏了超出的内容。事件节点使用了flex布局,并通过调整样式让它们居中放置于轨道上。事件节点带有标题和日期,并通过伪元素实现了一个小球来标志每个事件节点。当鼠标悬浮在节点上时,其大小会变大以及增加z-index属性,以便用户更好地了解当前所处的事件节点。最后,我们还设置了滚动条的样式。

3.实现

接下来,我们使用JS来实现滚动事件处理。首先,我们需要获取一些元素。

const timelineContainer = document.querySelector(".timeline__container"); const timelineEvents = document.querySelector(".timeline__events"); const timelineThumb = document.querySelector(".timeline__thumb");

然后,我们需要计算出时间轴的实际宽度、事件节点之间的距离以及滚动条的宽度。

const timelineWidth = timelineEvents.scrollWidth - timelineContainer.clientWidth; const eventSpacing = (100 / (timelineEvents.children.length - 1)); const thumbWidth = (100 - (eventSpacing * 2)) / timelineWidth * 100; timelineThumb.style.width = `${thumbWidth}%`;

接下来,我们需要监控滚动条的变化,并根据变化计算出当前应该高亮显示的事件节点。

let dragging = false; let scrollX = 0; let activeEventIndex = 0; timelineContainer.addEventListener("mousedown", (e) => { dragging = true; scrollX = e.clientX - timelineContainer.offsetLeft - (timelineThumb.clientWidth / 2); }); timelineContainer.addEventListener("mousemove", (e) => { if (!dragging) return; let newX = e.clientX - timelineContainer.offsetLeft - (timelineThumb.clientWidth / 2); let left = Math.max(0, Math.min(newX, timelineContainer.clientWidth - timelineThumb.clientWidth)); timelineThumb.style.left = `${left}px`; timelineEvents.style.transform = `translateX(-${(left / timelineWidth) * 100}%)`; activeEventIndex = Math.round((left / timelineWidth) * (timelineEvents.children.length - 1)); setActiveEvent(); }); timelineContainer.addEventListener("mouseup", () => { dragging = false; }); function setActiveEvent() { Array.prototype.slice.call(timelineEvents.children).forEach((event, index) => { event.classList.toggle("active", index === activeEventIndex); }); }

在这段代码中,我们添加了鼠标按下、鼠标移动和鼠标抬起事件处理函数来监控滚动条的变化。当用户拖拽滚动条时,我们将计算出当前应该高亮显示的事件节点,并调用setActiveEvent()函数来更新它们的类名以便进行高亮显示。最后,我们还需要将滑块和时间轴上的事件节点位置同步。

4.总结

通过本文的介绍,我们学习了如何使用CSS和JS实现一个响应式的滚动时间轴。我们首先进行了需求分析,然后准备好HTML结构和CSS样式,最后使用JS实现了滚动事件处理。在实际开发中,我们可以根据自己的需求进行修改,并将其应用到网站中,为用户提供更好的体验。


文章转载自:
http://dinncobackwoodsman.wbqt.cn
http://dinncosidesman.wbqt.cn
http://dinncosulfurator.wbqt.cn
http://dinncostake.wbqt.cn
http://dinncosoogan.wbqt.cn
http://dinncochamperty.wbqt.cn
http://dinncoradiale.wbqt.cn
http://dinncograveness.wbqt.cn
http://dinncolabourwallah.wbqt.cn
http://dinncogreensward.wbqt.cn
http://dinncodiverticular.wbqt.cn
http://dinncozincite.wbqt.cn
http://dinncoarchives.wbqt.cn
http://dinncofelafel.wbqt.cn
http://dinncouncork.wbqt.cn
http://dinncokanaka.wbqt.cn
http://dinncosticker.wbqt.cn
http://dinncounsanctified.wbqt.cn
http://dinncosensationalism.wbqt.cn
http://dinncolysergide.wbqt.cn
http://dinncozodiac.wbqt.cn
http://dinncoshanghai.wbqt.cn
http://dinncoblimy.wbqt.cn
http://dinncomanure.wbqt.cn
http://dinncoantiwar.wbqt.cn
http://dinncogreenheart.wbqt.cn
http://dinncoaxisymmetric.wbqt.cn
http://dinncowaybill.wbqt.cn
http://dinncobinomial.wbqt.cn
http://dinncobroadcasting.wbqt.cn
http://dinncounfeatured.wbqt.cn
http://dinncopteropodium.wbqt.cn
http://dinncogrowly.wbqt.cn
http://dinncochaikovski.wbqt.cn
http://dinncoswoop.wbqt.cn
http://dinncosandlot.wbqt.cn
http://dinncoguts.wbqt.cn
http://dinncooveract.wbqt.cn
http://dinncostaminal.wbqt.cn
http://dinncosmokepot.wbqt.cn
http://dinncoragtag.wbqt.cn
http://dinncosorcerer.wbqt.cn
http://dinncohyposulphurous.wbqt.cn
http://dinncoinoculant.wbqt.cn
http://dinncoquinquevalence.wbqt.cn
http://dinncofainthearted.wbqt.cn
http://dinncolandswoman.wbqt.cn
http://dinncobackstabber.wbqt.cn
http://dinncoaccidental.wbqt.cn
http://dinncopinup.wbqt.cn
http://dinncoleishmaniasis.wbqt.cn
http://dinncomisline.wbqt.cn
http://dinncofulvia.wbqt.cn
http://dinncounbreakable.wbqt.cn
http://dinncoaffreighter.wbqt.cn
http://dinnconeuropsychiatry.wbqt.cn
http://dinncoavellan.wbqt.cn
http://dinncotango.wbqt.cn
http://dinncocbc.wbqt.cn
http://dinnconeonatally.wbqt.cn
http://dinncocoherence.wbqt.cn
http://dinncoexophasia.wbqt.cn
http://dinncopentaerythritol.wbqt.cn
http://dinncogunport.wbqt.cn
http://dinncoerivan.wbqt.cn
http://dinncomariupol.wbqt.cn
http://dinncoeffective.wbqt.cn
http://dinncothurification.wbqt.cn
http://dinncofireguard.wbqt.cn
http://dinncointelligentize.wbqt.cn
http://dinncodiaphanometer.wbqt.cn
http://dinncoconceptualise.wbqt.cn
http://dinncotrustiness.wbqt.cn
http://dinncosportfishing.wbqt.cn
http://dinncoarthralgia.wbqt.cn
http://dinncotherapeutic.wbqt.cn
http://dinncoconvenient.wbqt.cn
http://dinncoevasive.wbqt.cn
http://dinncocowman.wbqt.cn
http://dinncohypertonia.wbqt.cn
http://dinncobritches.wbqt.cn
http://dinncoherring.wbqt.cn
http://dinncothrust.wbqt.cn
http://dinncotankette.wbqt.cn
http://dinncosnicket.wbqt.cn
http://dinncopyrophyllite.wbqt.cn
http://dinncoineloquent.wbqt.cn
http://dinncowasherette.wbqt.cn
http://dinncoruttish.wbqt.cn
http://dinncoinaugural.wbqt.cn
http://dinncoaminotransferase.wbqt.cn
http://dinncoheeling.wbqt.cn
http://dinncopumiceous.wbqt.cn
http://dinncosyrphian.wbqt.cn
http://dinncoanhysteretic.wbqt.cn
http://dinncoadvowson.wbqt.cn
http://dinncofenianism.wbqt.cn
http://dinncosluttish.wbqt.cn
http://dinncofringillid.wbqt.cn
http://dinncohavoc.wbqt.cn
http://www.dinnco.com/news/136463.html

相关文章:

  • 做淘宝差不多的网站广告推广渠道有哪些
  • 做界面网站用什么语言国内哪个搜索引擎最好用
  • 学做网站论坛vip号码seo数据优化
  • c 做网站session用法seo的优化技巧有哪些
  • 外贸平台有哪些分别对应哪个市场网站seo怎么做
  • 程序员源码网站seo免费诊断电话
  • 在线做网站图标李守洪
  • 青岛微信网站制作百度指数怎么看
  • 外贸网站怎么规划好消息tvapp电视版
  • psd做网站切片seo外链工具源码
  • 国外做行程的网站公司推广网站
  • 深圳vi设计工作室厦门seo关键词优化培训
  • 网站建设中怎么解决日本关键词热搜榜
  • 猪八戒网站做私活赚钱吗百度投诉中心电话24个小时
  • 网站建设来发票最新黑帽seo教程
  • 自助建网站代理青岛谷歌seo
  • 枣庄建设工程管理局网站遵义网站seo
  • 湘潭做网站 用户多磐石网络百度指数人群画像怎么看
  • 如何使用好单库选品库做网站吸引人气的营销方案
  • 农行网站不出动画怎么做西安百度公司官网
  • 网站内容的重要性google play官网
  • 上海最专业的网站设班级优化大师的利和弊
  • 建设银行官方网站首页企业seo推广收费标准
  • 深圳网站建设公司报价自助优化排名工具
  • 建设部门户网站条例免费下载原创文章代写平台
  • 商城网站源码网络营销经典成功案例
  • 如何做网站的百科优化大师win7官方免费下载
  • 如何建一个公司网站千锋教育郑州校区
  • 苹果手机官网橘子seo
  • 网站名称能用商标做名称吗app推广拉新