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

滚动导航 - unique

 

下面是效果图

ezgif-8ca4526462c724

下面是实现代码

 

<!DOCTYPE html>
<html lang="zh-CN"><head><meta charset="UTF-8" /><title>滚动导航 Demo</title><style>body {margin: 0;font-family: sans-serif;scroll-behavior: smooth;/* 平滑滚动 */}/* 顶部导航栏 */.navbar {position: fixed;top: 0;left: 0;width: 100%;background: #fff;border-bottom: 1px solid #eee;display: flex;justify-content: center;gap: 20px;padding: 10px 0;z-index: 1000;}.navbar a {color: #555;text-decoration: none;padding: 6px 10px;border-radius: 4px;}.navbar a.active {color: #fff;background: #409eff;}/* 内容区 */section {height: 100vh;padding-top: 60px;/* 避免被导航栏遮挡 */box-sizing: border-box;}section:nth-child(odd) {background: #f6f6f6;}section:nth-child(even) {background: #e8f1ff;}</style>
</head><body><!-- 顶部导航栏 --><div class="navbar" id="navbar"><a href="#s1">首页</a><a href="#s2">功能</a><a href="#s3">关于</a></div><!-- 页面内容 --><section id="s1"><h2>首页</h2></section><section id="s2"><h2>功能介绍</h2></section><section id="s3"><h2>关于我们</h2></section><script>const links = document.querySelectorAll('.navbar a');const sections = Array.from(links).map(a => document.querySelector(a.getAttribute('href')));const observer = new IntersectionObserver((entries) => {entries.forEach(entry => {if (entry.isIntersecting) {links.forEach(link => link.classList.toggle('active', link.getAttribute('href').slice(1) === entry.target.id));}});}, { threshold: 0.6 }); // 进入视口 60% 时高亮
sections.forEach(s => observer.observe(s));</script>
</body></html>

 

http://www.hskmm.com/?act=detail&tid=26701

相关文章:

  • windows剪切板工具
  • P1545 [USACO04DEC] Dividing the Path G 题解
  • 视频采集程序
  • java作业2
  • 关于PPT的课后作业
  • RK 系列 GPU 驱动检查方法
  • 咕乡
  • Linux随记(十八) - 详解
  • week2课后作业
  • Java 语言程序设计(第二讲 方法)动手动脑与课后实验问题整理文档 - 20243867孙堃2405
  • 算法第一章
  • mac打开app提示文件损坏解决方案
  • QBXT2025S刷题 Day7题
  • 无需重新训练即可更新语音识别词汇
  • 深入解析:vscode中无法使用npm node
  • 第一次算法作业
  • AI元人文:新的评价与启示
  • Ai元人文:岐金兰回应
  • Why is English commonly used in scientific literature?
  • 第二次课程
  • 考研系列—操作系统:冲刺笔记(1-3章) - 指南
  • 智能照明系统厂家最新推荐榜:智慧光控与节能方案口碑之选
  • 2025工业网线优质厂家最新推荐榜:品质卓越与技术领先之选
  • 上海殡葬一条龙服务最新推荐:专业关怀与人性化服务口碑之选
  • 中空扳手实力厂家最新推荐榜:专业制造与耐用品质深度解析
  • 驾驭“人造太阳”:用 AI 来解锁聚变核能
  • sg.Multiline 和 sg.Output 有什么区别?怎么看起来一样?
  • 中科微GNSS卫星定位产品
  • 算法设计与分析第一章作业
  • Syncfusion重构Essential Studio套件,为开发者提供更灵活选择