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

网站建设协调会彩票网站搭建多钱

网站建设协调会,彩票网站搭建多钱,响应式网站建设流程,青岛建设工程信息网站随着互联网的发展#xff0c;网站的界面设计越来越重要。吸引用户的关注、提高用户体验已经成为了许多网站的目标。而在实现各种复杂的界面效果中#xff0c;CSS与JS的组合无疑是开发者的得力工具。本文将介绍如何使用CSS和JS实现一个响应式的滚动时间轴。 1.需求分析 在开…随着互联网的发展网站的界面设计越来越重要。吸引用户的关注、提高用户体验已经成为了许多网站的目标。而在实现各种复杂的界面效果中CSS与JS的组合无疑是开发者的得力工具。本文将介绍如何使用CSS和JS实现一个响应式的滚动时间轴。 1.需求分析 在开始实现之前我们需要分析出需求。首先我们需要一个时间轴的框架其中包含一系列的事件节点这些事件节点可以根据滚动条的位置来进行滚动。其次在滚动条滚动期间我们需要将当前事件节点高亮显示以便用户更好地了解当前所处的时间位置。最后如果用户拖拽滚动条时我们需要平滑地接过控制权并根据滚动条位置来定位事件节点。 2.准备工作 在开始实现之前我们需要做一些准备工作。首先我们需要准备好HTML结构包括时间轴框架、事件节点等元素其次我们需要使用CSS样式来美化这些元素并且确保它们能正确地显示在页面上最后我们需要使用JS来控制滚动条的位置并根据其位置来定位事件节点。下面是我们需要准备的HTML结构 div classtimeline__container div classtimeline__track ul classtimeline__events li classtimeline__event styleleft: 0; div classtimeline__event_titleEvent 1/div div classtimeline__event_date2023-05-03/div /li li classtimeline__event styleleft: 20%; div classtimeline__event_titleEvent 2/div div classtimeline__event_date2023-05-04/div /li li classtimeline__event styleleft: 40%; div classtimeline__event_titleEvent 3/div div classtimeline__event_date2023-05-05/div /li li classtimeline__event styleleft: 60%; div classtimeline__event_titleEvent 4/div div classtimeline__event_date2023-05-06/div /li li classtimeline__event styleleft: 80%; div classtimeline__event_titleEvent 5/div div classtimeline__event_date2023-05-07/div /li /ul div classtimeline__scrollbar div classtimeline__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://www.hkea.cn/news/14258673/

相关文章:

  • 二手物品交换网站建设关键词搜索量怎么查
  • wordpress网站语言适合新手做网站的
  • 软文营销模板慈溪网站优化
  • 都匀住房和城乡建设局网站外贸网站APP
  • 廊坊模板建站代理wordpress字不能显示
  • 商务网站建设与维护论文做平行进口的汽车网站
  • 公司的网站推广怎么做企业营销策划合同范本
  • 如何进行网站icp备案上线一个网站需要多少钱
  • 搜狗站长工具平台wordpress极验证登录
  • 简单的个人主页网站制作wordpress ftp
  • 公司网站域名续费一年多少钱开发app平台需要多少钱
  • 这么自己做网站关于解决网站 建设的请示
  • 做网站能用ai做吗dede织梦做的网站 栏目页有切换js 怎么循环子栏目 调子栏目
  • 网站建设费用IPwordpress添加语系
  • 网上做设计的网站徐州网站公司
  • 杭州做网站公司有哪些青岛网站制作公司 网络服务
  • c语言做网站网站不备案可以登录吗
  • 婚恋网站的架构莱芜最新话题
  • 天河网站建设优化浏览网站怎么用手机做
  • 怎么让网站无法自适应西华县住房和城乡建设局网站
  • 德宏网站建设公司网页美工设计招聘
  • 超凡网络网站房产网站门户系统
  • 贷款网站建设方案wordpress如何手动安装主题
  • 湖州网站建站如何更换网站服务商
  • 做请柬的网站微信采集wordpress
  • 做网站被用作非法用途cpa没有网站怎么做
  • 在网站做电子画册无锡网站建设团队
  • 昆明乐网网站建设网站由哪些部分组成
  • 怎么一个网站做的竞价莱芜在线广告信息
  • 专业的营销型网站制作音乐网站 模板